package contorller;
import java.sql.*;
public class MySqlDB {
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
int effectRow=0;
public void connectionDB() {
try{
Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/111?useSSL=false&serverTimezone=UTC&charterEncoding=utf_8&","root","123456");
//123456是自己设置的密码
}catch(ClassNotFoundException e) {
System.out.println("找不到驱动类");
e.printStackTrace();
}catch(SQLException e) {
System.out.println("数据库连接异常");
e.printStackTrace();
}
}public void closeDB() {
try
{
if(rs!=null)rs.close();
if(stmt!=null)stmt.close();
if(conn!=null)conn.close();
}catch(SQLException e) {
System.out.println("关闭数据库异常");
e.printStackTrace();
}
}
}