Forums Register Login

PreparedStatement sucks

+Pie Number of slices to send: Send
I thought I had a great idea. I could extract all of my SQL execution code into one class, and pass that class a connection, a String SQL statement with '?'s marking the parameters, and an array of Java Objects, use a loop to iterate through the Objects and use PreparedStatement.setObject() to set the values from the array and I'm done, right?
Nope. PreparedStatement doesn't handle null objects. One must call PreparedStatement.setNull(). And one cannot just pass null, one must pass the java.sql.Type value for the column type for this method. But I don't know the type, because I can't get the class of a null handle.
Anybody out there figure out a good abstraction layer between Java objects and database tables? I've run into this kind of thing a couple times.
+Pie Number of slices to send: Send
 

Originally posted by Joe Ess:
Anybody out there figure out a good abstraction layer between Java objects and database tables? I've run into this kind of thing a couple times.

Ah, the famous impedance mismatch between RDBMSs and Java objects; don't we all love to hate it? But there are some decent impedance adapters around:
  • CocoBase one of the market leaders in transparent persistence
  • TopLink another market leader in transparent persistence
  • Sun Transparent Persistence, formerly JavaBlend, comes with the Forte development environment (including the Community Edition)
  • ObjectSpark can map both to JavaBeans and COM components
  • FrontierSuite (EJB-based)
  • JRelay
  • KodoJDO based on Sun JDO, still in beta
  • And the open-source brigade:
    • Castor is the premier open source JDO-style framework; maps to RDBMS, XML and JNDI, and supports the OQL query language
    • Turbine includes the Torque OR mapper
    • JRelationalFramework
    • ObjectRelationalBridge based on the ODMG standard
    • Osage generates persistent classes
    • Expresso is a complete commercially supported application framework that includes an OR mapper
    • HTH,
      - Peter
      [This message has been edited by Peter den Haan (edited October 30, 2001).]
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1281 times.
Similar Threads
SQLException: Invalid column type when setting null values to NUMBER type columns
How to insert cachedrowset data into MS Access Database?
Implementing ArrayList class manually
Need a disconnected resultset
Excess functionality?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:33:42.