首页 > 代码库 > DButil

DButil

public class DBUtil {
    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");

        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
           
e.printStackTrace();
        }
    }


    public static  Connection getConnection(){
        Connection conn=null;
        try {
            conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/apartmentsystemdb", "root", "admin");

        } catch (SQLException e) {
            // TODO Auto-generated catch block
           
e.printStackTrace();
        }
        return conn;
    }
    public static  void close(Connection conn){
        try {
            conn.close();

        } catch (SQLException e) {
            // TODO Auto-generated catch block
           
e.printStackTrace();
        }
    }
}

 

DButil