MySQL--JDBC

Source: Internet
Author: User

First, the development steps of JDBC

1. Prepare four parameters

2. Registered Driver

3. Get the connection

4. Get the statement performer

5. Execute SQL statements

6. Processing results

7. Releasing Resources

1. Prepare four parameters

/*   * JDBC Four configuration parameters    * > DriverClassName:java.mysql.jdbc.Driver  --Driver class name  * > url:jdbc:mysql:// localhost:3306/database name    * > Username:root   * > Password:  */string Driverclassname="java.mysql.jdbc.Driver"; String URL="jdbc:mysql://localhost:3306/sine"; String username="root"= "";

2. Registered Driver

Class.forName ("com.mysql.jdbc.Driver"); // Load Driver class  = =Drivermanager.registerdriver (new com.mysql.jdbc.Driver ());

Because in the Com.mysql.jdbc.Driver implementation class, there is a static code block, that is, the code that executes the static code block when the class is loaded.

3. Get the connection

// Connection Object Connection conn = (Connection) drivermanager.getconnection (URL, user, password);

4. Get the statement performer

/* *  Create statement * >  statement statement Sender via Connection object, its function is to send SQL statement to database * */= Conn.createstatement ();

5. Execute SQL statements

//   call it int executeupdate (String sql), which can execute DML, DDL= "INSERT into user values ('", ' eager ', ' 1999-09-09 ', ' n ', ' smile '); int r = stmt.executeupdate (SQL);

6. Processing results


7. Releasing Resources

MySQL--JDBC

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.