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 ;}