After creating the connection with JDBC, the SQL execution needs to be created statement
Statement stmt = Connection.createstatement ();
Create the code as follows
PublicJava.sql.Statement createstatement ()throwsSQLException {returncreatestatement (Java.sql.ResultSet.TYPE_FORWARD_ONLY, Java.sql.ResultSet.CONCUR_READ_ONLY); }//default Query results forward loop, read-only query results PublicJava.sql.Statement createstatement (intResultsetType,intresultSetConcurrency)throwsSQLException {
Check if connection is off checkclosed (); Statement stmt=NewCom.mysql.jdbc.Statement ( This, This. database); Stmt.setresultsettype (ResultsetType); Stmt.setresultsetconcurrency (resultsetconcurrency); returnstmt; }
When you execute query sql:
ResultSet rs = stmt.executequery ("test");
The returned resultset data is stored in RowData (Protected RowData rowdata).
After executing next is an array of objects.
The statement shutdown method, which, by default, closes the statment while closing the resultset.
public void Close () throws SQLException {Realclose (True, true);}
.....
This.isclosed = true;
.....
----------------------------------------------------
1. Create a connection to the MySQL server when drivermanager.getconnection
2, statement share the same connection.
3, close connection when the connection will be connected, will also call the relationship All statement method Closeallopenstatements ().
MYSQL-JDBC creating statement and executing SQL