If you REALLY REALLY want to go through the fields of a class (BadUhm, why? I'm quite sure, we are not alone here with the need to have an
Idea)
object for every row return by an SQL-query...
you can use reflection.Well, here is what I cooked up:
http://aldan.algebra.com/~mi/selfset...mSQL.java.html
or
http://aldan.algebra.com/~mi/selfset...ngFromSQL.java
It will set the scalar fields and even arrays. The same java.sql.ResultSet
can be used to create (or set) different objects -- the columns without
matching fields in each object's class will simply be ignored.
A typical use would be to define your own class as "extends
SelfSettingFromSQL".
Hibernate does exactly what you want. Exactly what you want. Let meNOW, I can go and look into how someone else has done it :)
repeat. Hibernate does exactly what you're trying to do.
Just know that I've gone down the road you're trying to. It isn't aSo far I like it :) All I need now is declare the data-fields in my classes
pretty journey, and the destination isn't all that nice either.
and make sure, the SQL-queries return fields with matching names. The
tedious setting of every field (in every one of those classes) is now a
thing of the past.
The information about all the names and the types of all the fields is there
at run-time. Not using it is foolish...
-mi