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

public class DBUtil {
//mysql数据库驱动
private final static String DRIVER="org.gjt.mm.mysql.Driver";

//数据库连接字符串
private final static String URL="jdbc:mysql://localhost:3306/db";

//用户名
private final static String USERNAME="root";

//密码
private final static String PASSWORD="57694187";

private static Connection conn;

public static Connection getConnection(){
try{
Class.forName(DRIVER);
conn=DriverManager.getConnection(URL,USERNAME,PASSWORD);
}catch (ClassNotFoundException e) {
e.printStackTrace();
}catch (SQLException e) {
e.printStackTrace();
}
return conn;
}

public static void close(){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

 

相关文章:

  • 2021-10-19
  • 2021-10-18
  • 2022-02-07
  • 2021-08-25
  • 2022-01-01
  • 2021-05-15
  • 2021-07-07
  • 2021-10-29
猜你喜欢
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案