- Return Auto Generated Key Queryjdbc Mysql Java 10
- Return Auto Generated Key Query Jdbc Mysql Java Tutorial
Specifically, this method uses some Spring JDBC classes and methods to (a) execute a SQL INSERT statement, (b) get the generated id from the database for the record I just inserted (i.e., the value of the autoincrement field in a MySQL database table), and (c) return that integer value at the end of the method. Create a table that contains an AUTOINCREMENT column. Write a simple sp that inserts a record into this table. Call the sp using the 'RETURNGENERATEDKEYS' value in the prepareStatement function. Attempt to obtain the new insert ID value using the getGeneratedKey function. The resultset is empty.
List: | MySQL and Java | ||
From: | Christopher Taylor | Date: | January 8 2003 1:32pm |
Subject: | Re: retrieving auto-generated keys on bulk insert | ||
View as plain text |
Thread | ||
---|---|---|
• retrieving auto-generated keys on bulk insert | Dane Foster | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Mark Matthews | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Paul DuBois | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Dane Foster | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Mark Matthews | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Paul DuBois | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Christopher Taylor | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Jeff Mathis | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Dane Foster | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Dane Foster | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Jeff Mathis | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Dane Foster | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Paul DuBois | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Jeff Mathis | 8 Jan |
• Re: retrieving auto-generated keys on bulk insert | Tim Endres | 9 Jan |
• Re: retrieving auto-generated keys on bulk insert | Dane Foster | 8 Jan |
Return Auto Generated Key Queryjdbc Mysql Java 10
-->Return Auto Generated Key Query Jdbc Mysql Java Tutorial
The Microsoft JDBC Driver for SQL Server supports the optional JDBC 3.0 APIs to retrieve automatically generated row identifiers. The main value of this feature is to provide a way to make IDENTITY values available to an application that is updating a database table without a requiring a query and a second round-trip to the server.
Because SQL Server doesn't support pseudo columns for identifiers, updates that have to use the auto-generated key feature must operate against a table that contains an IDENTITY column. SQL Server allows only a single IDENTITY column per table. The result set that is returned by getGeneratedKeys method of the SQLServerStatement class will have only one column, with the returned column name of GENERATED_KEYS. If generated keys are requested on a table that has no IDENTITY column, the JDBC driver will return a null result set.
As an example, create the following table in the sample database:
In the following example, an open connection to the sample database is passed in to the function, an SQL statement is constructed that will add data to the table, and then the statement is run and the IDENTITY column value is displayed.