![mysql jdbc get auto increment value mysql jdbc get auto increment value](https://i.ytimg.com/vi/tiP3pg_rfro/maxresdefault.jpg)
Register the Driver class of the desired database using the registerDriver() method of the DriverManager class or, the forName() method of the class named Class.ĭriverManager.registerDriver(new ()).Now, to insert multiple records into this table by executing the multiple-row INSERT statement using Statement object and, to retrieve the auto-incremented values generated by it − Let us create a table with name sales in MySQL database, with one of the columns as auto-incremented, using CREATE statement as shown below − CREATE TABLE Sales( You can retrieve the values of that particular column, generated by the current Statement object using the getGeneratedKeys() method. If you insert records into a table which contains auto-incremented column, using a Statement object. Retrieving the auto-incremented generated by the Statement object (You can specify the initial value and interval for these auto-incremented columns). When you insert the next record using the INSERT statement the ID value of the new record will be 7 and the ID value of its next record will be 8. These will be generated automatically.įor example, in a table if we have a column with name ID and data type INT, which is auto-incremented and, if we already have 6 records in that table. While inserting records in a table there is no need to insert value under the auto-incremented column. In MySQL database you can declare a column auto increment using the following syntax. Various databases support this feature in different ways. While creating a table, in certain scenarios, we need values to column such as ID, to be generated/incremented automatically.