• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PreparedStatement sucks

 
Joe Ess
Bartender
Posts: 9340
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic