jdbc工具
package Dao;
import java.sql.*;
public class JDBC {
static final String url="jdbc:mysql://localhost:3306/syfwfl?useSSL=false&serverTimezone=UTC";
static final String user="root";
static final String password="19980605";
static PreparedStatement pre=null;
static ResultSet res=null;
static Connection conn=null;
//注册驱动
static {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//获取连接
public static Connection getconnection(){
try {
conn= DriverManager.getConnection(url,user,password);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return conn;
}
//创建mysql操作对象
public PreparedStatement createStatement(String sql){
try {
conn=getconnection();
pre=conn.prepareStatement(sql);
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return pre;
}
public void search(){}
public static void close(){
if (res!=null) {
try {
res.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if (pre!=null) {
try {
pre.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if (conn!=null) {
try {
conn.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
}