Jdbc connects to the mysql database and executes the insert statement to obtain the self-increasing primary key value. jdbcmysql

Source: Internet
Author: User

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 ();}}}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.