File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Insert Query with auto-incrementing key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Insert Query with auto-incrementing key" Watch "Insert Query with auto-incrementing key" New topic

Insert Query with auto-incrementing key

Chris Weathers

Joined: May 06, 2005
Posts: 12
I have a users table with a primary key "id" that is set to auto-increment for new insertions. So a new user gets automatically assigned the number of users + 1 for their id.

How does my query from my jsp change in this situation? Do I just leave off the "id" field in the Insert query?
Samuel Cox
Ranch Hand

Joined: Nov 16, 2004
Posts: 96

For oracle, mysql, sqlserver, db2?

For db2, I think we used identity_val_local or something like that. For sqlserver, you leave it off.

I agree. Here's the link:
subject: Insert Query with auto-incrementing key
jQuery in Action, 3rd edition