• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

extending java.sql.Connection?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
I know that the db-driver (mySQLjdbc.jar e.g.) implements the connection interface. I would like to add new functions to a connection, such as retrieving unique keys. How do I do that?
Thanks in advance,
Rolf Mueller
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure this sort of thing is possible. The connections are returned from the drivers provided by the database vendor. So, even though you can implement your own connection or somehow extend the connection returned by your driver's implementation, there's no way to force your driver to use the newly improved connection.
You would basically have to hack all the little pieces of your driver to do the whole thing (using the connection and everything else). Of course, at that point, you wouldn't be using a JDBC-compliant driver, which would bring more misery to your life.
On a plus side, JDBC3 lets you retrieve generated primary keys. In earlier versions (I'm assuming you're using mySQL), the mySql driver let you cast something so you could retrieve the generated primary key for inserts. My point: make sure you thoroughly research what you need and other ways to get what you want. Just because you can develop yourself some solution doesn't mean there aren't other, much-easier ways of doing the same thing.
 
Rolf Mueller
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for posting this without having a morning cafe
Now I found an easy solution, which seems to work. Looks like that:


I use this class in my connection-pool, and can use the added functionality in my persistence-controler.
[ March 22, 2004: Message edited by: Rolf Mueller ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic