Linked Questions
102 questions linked to/from How to get the insert ID in JDBC?
102 votes
2 answers
185k views
MySQL & Java - Get id of the last inserted value (JDBC) [duplicate]
Possible Duplicate: How to get the insert ID in JDBC? Hi, I'm using JDBC to connect on database through out Java. Now, I do some insert query, and I need to get the id of last inserted value (so,...
62 votes
14 answers
116k views
How to get a value from the last inserted row? [duplicate]
Is there some way to get a value from the last inserted row? I am inserting a row where the PK will automatically increase, and I would like to get this PK. Only the PK is guaranteed to be unique in ...
39 votes
3 answers
59k views
Java PreparedStatement retrieving last inserted ID [duplicate]
This answer to this question done this way seems to be very difficult to find on the internet. Basically I am inserting values into a MySQL database using PreparedStatement. I use the ...
13 votes
2 answers
18k views
SQL (Java, h2): What's the best way to retrieve the unique ID of the single item I just inserted into my database? [duplicate]
My current method is this: SELECT TOP 1 ID FROM DATAENTRY ORDER BY ID DESC This assumes the latest inserted item always has the highest unique ID (primary key, autoincrementing). Something smells ...
9 votes
8 answers
11k views
Obtain id of an insert in the same statement [duplicate]
Is there any way of insert a row in a table and get the new generated ID, in only one statement? I want to use JDBC, and the ID will be generated by a sequence or will be an autoincrement field. ...
5 votes
1 answer
8k views
SQL java get value assigned to auto increment primary key [duplicate]
I have a primary key auto increment attribute in my table. I want to know the value assigned to it for a row that is inserted using statement.executeUpdate(). How to achieve this in the best possible ...
5 votes
1 answer
13k views
Returning generated keys in MySql with JDBC PreparedStatement [duplicate]
I'm programming with plain JDBC a DAO layer because I only have 61.38 MB on Java Memory in my Tomcat (service hosting). I have a table with an AUTO_INCREMENT column in MySQL. The current ...
1 vote
3 answers
3k views
Getting the last inserted record id of a database table in java? [duplicate]
I have a database table A which stores records, A has a primary key (recordid) with auto_increment, each time i insert a record in to A, i get the inserted recordid and store it in another ...
0 votes
1 answer
4k views
How to get last inserted ID as Long in java mysql [duplicate]
I want to get the last inserted ID as long. Because the primary key of my table is of long data type. Here's my code: Connection connection = null; Statement statement = null; ...
0 votes
4 answers
409 views
How do I get ID of row i just inserted in Java [duplicate]
Ok so my code looks like this String sqlString = "INSERT into auditlog(report_name, username, start_datetime, resource_uri, resource_id) VALUES (?,?,?,?,?)"; preparedStatement = ...
0 votes
2 answers
2k views
How to get the ID of auto generated id from the Database [duplicate]
Possible Duplicate: How to get the insert ID in JDBC? I have the following tables: customer(cid, ...) book(cid, rid) reservation(rid, ...) I want to add a reservation in its table then I want ...
0 votes
3 answers
2k views
How to use LAST_INSERT_ID() Equivalent of @@IDENTITY in MySql [duplicate]
In MySql, I want to use equivalent of SQL @@IDENTITY and I found this LAST_INSERT_ID(). I found in search that it work fines even if there are different sessions exist. I want to find last ID,in ...
0 votes
2 answers
2k views
How to fetch an id from the database after record inserted in db [duplicate]
How to fetch id from db using JSP servlet. This is my JSP servlet code and I need code for display id through alert message box and in my db I will gave id as auto-increment in data base. I ...
0 votes
1 answer
2k views
Retrieving the last inserted Identity ID from a table using the Statement.RETURN_GENERATED_KEYS routine? [duplicate]
Possible Duplicate: How to get the insert ID in JDBC? In the following statement, how can I fetch the last inserted C12 identity value? This is from the JavaDB manual, but they have not mentioned ...
1 vote
1 answer
1k views
Get the value of an auto-increment-field within the transaction [duplicate]
I'm using H2DB for a litthe cuesheet-database. I'm inserting several records to a table with anj auto-increment field for the primary key ID. For each record I want to know the value of the ID-field ...