• 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

How to return Primary Key (autonumber) after an Insert

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am developing an Intranet system. Anyway I'm purely using JSPs to do it. And I have no problem doing the usual SQL commands. However, I have a problem now. I need to return the automatically incremented Primary Key after I insert a new record. I have also developed web apps using ASP before and used the cursor bookmarks. JSP is a tad different so if someone could help me, I'd be forever in their debt!!
Other Information:
I'm using DB2 as my database.
Using Websphere Studio as my development environment.
Using Websphere Test Environment (in VAJ) to run the JSPs.
Thanks in Advance!
-Tony
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unlike ASP, Java code is expected to be able to "run anywhere", which often means not supporting features that are unique to a given vendor's DBMS, such as auto-incrementing keys (I know it's a common feature, but it's not in the SQL standard). So from a purely portable perspective, there's nothing you could latch on to. For a particular vendor's DBMS, however, you may find an extra driver function or the like - check their jdbc docs. Or, if you're using SQL Server, someone else's jdbc docs, since Microsoft doesn't provide a Java driver.
This problem gets even worse when working with Enterprise JavaBeans, where the key is expected to be known BEFORE the record is added - so much so, that I expect Sun will eventually have to provide a rathole for it.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic