Package CN.ITCAST.JDBC;
Import java.sql.Connection;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.sql.Statement;
Import Cn.itcast.jdbc.dataSource.MyDataSource2;
Public final class Jdbcutils {private static MyDataSource2 myDataSource = null;
Private Jdbcutils () {} static {try {Class.forName ("com.mysql.jdbc.Driver");
myDataSource = new MyDataSource2 ();
} catch (Exception e) {throw new Exceptionininitializererror (e); }} public static Connection getconnection () throws SQLException {//Return drivermanager.getconnection (
URL, user, password); return Mydatasource.getconnection (); Fetch connection} public static void Free (ResultSet rs, Statement St, Connection conn) {try {if (RS
! = null) rs.close ();
} catch (SQLException e) {e.printstacktrace (); } finally {try {if (ST! = NULL) st.close ();//Now the Close method is to put the connection back into the connection pool instead of closing the connection} catch (SQLException e) {
E.printstacktrace ();
} finally {try {if (conn! = null) conn.close ();
} catch (Exception e) {e.printstacktrace (); }
}
}
}
}