MYSQL-JDBC creating statement and executing SQL

Source: Internet
Author: User

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

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.