Connecting Tech Pros Worldwide Help | Site Map

Self-setting from SQL

  #1  
Old December 12th, 2007, 11:15 PM
Mikhail Teterin
Guest
 
Posts: n/a
Daniel Pitts wrote:
Quote:
If you REALLY REALLY want to go through the fields of a class (Bad
Idea)
Uhm, why? I'm quite sure, we are not alone here with the need to have an
object for every row return by an SQL-query...
Quote:
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".
Quote:
Hibernate does exactly what you want. Exactly what you want. Let me
repeat. Hibernate does exactly what you're trying to do.
NOW, I can go and look into how someone else has done it :)
Quote:
Just know that I've gone down the road you're trying to. It isn't a
pretty journey, and the destination isn't all that nice either.
So far I like it :) All I need now is declare the data-fields in my classes
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
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
One SQL to test multiple records Ivor Somerset answers 2 December 8th, 2006 08:25 AM
Download the JAVA , .NET and SQL Server interview with answers Jobs answers 2 September 26th, 2006 02:25 PM
Download the JAVA , .NET and SQL Server interview PDF Jobs answers 0 September 17th, 2006 02:05 PM
error downloading .pdf from SQL database Matt Mercer answers 2 November 18th, 2005 06:58 PM
Foreign Key self-join on a DataTable Ev answers 2 November 16th, 2005 10:51 PM