Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Build SQL Statements

 
Lou Pelagalli
Ranch Hand
Posts: 150
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm looking for a class that will accept an instance of java.sql.ResultSetMetaData and return a String or other object suitable for use as an SQL Insert statement.
Any suggestions?
Thank You in Advance for Your Help,
Lou
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the JDBC forum.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not aware of anything like that. It might be a fun exercise to build. You could step through the column metadata and build up an insert statement as a string. You could return a prepared statement ready for a client to plug in values for the ? in the SQL. Aside from the fun, I'm not sure it would be real useful, tho. Do you have a good application for it?
I made something as a class project once that parsed DDL and generated inserts on the fly to create random test data. DDL has everything your metadata has plus relationships. The program knows about foreign keys and can either use existing values in the referenced table or insert rows there first. It was entertaining to build and got a good grade, but I've never been the least bit tempted to use it.
 
Lou Pelagalli
Ranch Hand
Posts: 150
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stan,
I've ended up writing the class myself. I would have been a bit surprised to find one. I spin through the send the resultSet of to a Singleton class that then gets the metadata and depending on the method called returns the Create or Insert statement, and the insert includes the data.
Why?
Follow this url: http://hsqldb.sourceforge.net/ This takes a table and writes it to memory using SQL statements. Then for fast processing I can read the data in memory via more SQL.
If you want the full story then go here: http://www.coderanch.com/t/372313/java/java/Dimensional-Hashtable. Jim's reply posted on November 23, 2003 03:18 PM got me moving in this direction.
Thanks for Your Reply,
Lou
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic