DBUtil

package utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**

  • 该类用户获取数据库连接对象以及关闭连接
  • @author Administrator

*/
public class DBUtil {

public static Connection getConnection(){
    Connection conn=null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        conn=DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/neuedu?useUnicode=true&characterEncoding=utf8", 
                "root","root");
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return conn;
}
public static void closeConn(Connection conn){
    try {
        conn.close();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

你可能感兴趣的:(DBUtil)