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
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
Forum:
JDBC and Relational Databases
how to retrieve the new ID of the auto_increment column
Keya Shah
Greenhorn
Posts: 3
posted 19 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: 67746
173
I like...
posted 19 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 19 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
Quick! Before anybody notices! Cover it up with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
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...