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