Jdbc-how does the JDBC encapsulation class of mysql release resources?

Source: Internet
Author: User
Returns a Resultset result in this class and loops it out in another class. Is there any way to directly release resources in this class? If finally {...} is added directly to the end {...} an error will be reported. for beginners, solve publicResultSetSQL_ExecuteQuery (Stringsql, Object [] p) {ConnectionconopenConnection (); open database PreparedStatementpstnull; define an execution Object ResultSetrstnull; try {... mysqljdbcjava

Returns a Resultset result in this class and loops it out in another class. Is there any way to directly release resources in this class? If finally {...} is added directly to the backend, an error is returned.

Public ResultSet SQL _ExecuteQuery (String SQL, Object [] p)
{
Connection con = openConnection (); // open the database
PreparedStatement pst = null; // defines an execution object
ResultSet rst = null;
Try {
Pst = con. prepareStatement (SQL); // initialize the execution object
// Cyclically set parameters
If (p! = Null & p. length> 0)
{
For (int I = 0; I <p. length; I ++ ){
Pst. setObject (I + 1), p [I]); // set parameters
}
}
Rst=pst.exe cuteQuery ();
// Finally execute the command and return the result
Return rst; // execute the command
} Catch (SQLException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}

Return null ;}

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.