JDBC 工具类封装
package cn.tedu;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class DBUtils {
public static Connection getConnection() throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql:///jt_db?characterEncoding=utf-8"
,"root",
"1234"
);
return conn;
}
public static void close(ResultSet rs, Statement stat,Connection conn){
if (rs!=null){
try {
rs.close();
}catch (Exception e){
e.printStackTrace();
}finally {
rs=null;
}
}
if (stat!=null){
try {
stat.close();
}catch (Exception e){
e.printStackTrace();
}finally {
stat=null;
}
}
if (conn!=null){
try {
conn.close();
}catch (Exception e){
e.printStackTrace();
}finally {
conn=null;
}
}
}
}