Jdbc connects to the mysql database and executes the insert statement to obtain the self-increasing primary key value. jdbcmysql
Package cn. baokx; import java. SQL. connection; import java. SQL. preparedStatement; import java. SQL. resultSet; import java. SQL. SQLException; import java. SQL. statement; import cn. baokx. db. databaseConnection0; public class Test1 {public static void main (String [] args) {Connection conn = new DatabaseConnection0 (). getConnection (); PreparedStatement pst = null; ResultSet rs = null; String SQL = "INSERT INTO dz (date, time, s, w, deep, level, location) "+" VALUES ('2017-01-01 ', '05: 03: 44', 2014, 25.6, 122.4, 260, 'Russian') "; try {pst = conn. prepareStatement (SQL, statement.return_generated_keys1_1_pst.exe cuteUpdate (); rs = pst. getGeneratedKeys (); if (rs. next () {System. out. println (rs. getObject (1) ;}} catch (SQLException e) {e. printStackTrace ();} finally {try {rs. close (); pst. close (); conn. close ();} catch (SQLException e) {// TODO Auto-generated catch blocke. printStackTrace ();}}}}