Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud
this week in the
Cloud/Virtualization
forum!
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
Tim Cooke
paul wheaton
Paul Clapham
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Saloon Keepers:
Tim Holloway
Carey Brown
Roland Mueller
Piet Souris
Bartenders:
Forum:
JDBC and Relational Databases
how to retrieve the new ID of the auto_increment column
Keya Shah
Greenhorn
Posts: 3
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am using mysql database.
In my
jsp
page, after inserting a record in the mysql table, I need to get back the new ID generated for the auto_increment primary key column. How do I get this value?
Any help appreciated.
Bear Bibeault
Sheriff
Posts: 67756
173
I like...
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Not a JSP question; moving along to the
JDBC
forum.
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
Roberto Spier
Greenhorn
Posts: 7
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello, Keya,
I do it this way:
String[] keys = {"id"}; // define an array of table's primary keys stmt.executeUpdate(sql, keys ); ResultSet rs = stmt.getGeneratedKeys(); if (rs.next()) { id = rs.getInt(1); }
HTH
Roberto
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
last_insert_id()
MySQL auto increment
MySQL AUTO_INCREMENT column not uniform
A problem with Hibernate and MySQL query.
auto_increment primary key
More...