package connectionutil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionUtil {
private static String URL="jdbc:mysql://localhost:3307/scott"+"?useSSL=false&useUnicode=true"+"&characterEncoding=UTF-8&serverTimezone=UTC";
// private static String URL = "jdbc:mysql://localhost:3307/scott" +"?useUnicode=true&useJDBCCompliantTimezoneShift=true"+"&useLegacyDatetimeCode=false&serverTimezone=UTC";
private static String DRIVER="com.mysql.cj.jdbc.Driver";
private static String USER = "biubiu";
private static String PASSWORD = "123456";
//加载驱动
static{
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConnection(){
try {
return DriverManager.getConnection(URL,USER,PASSWORD);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static void close(Connection conn){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package connectionutil;
import java.io.Serializable;
import java.util.Date;
public class Emp implements Serializable {
private Integer empno;
private String ename;
private String job;
private Integer mgr;
private Double sal;
private Date hiredate;
private Double comm;
private Integer deptno;
public Emp() {
}
public Emp(Integer empno, String ename, String job, Integer mgr, Double sal, Date hiredate, Double comm, Integer deptno) {
this.empno = empno;
this.ename = ename;
this.job = job;
this.mgr = mgr;
this.sal = sal;
this.hiredate = hiredate;
this.comm = comm;
this.deptno = deptno;
}
public Integer getEmpno() {
return empno;
}
public void setEmpno(Integer empno) {
this.empno = empno;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public Integer getMgr() {
return mgr;
}
public void setMgr(Integer mgr) {
this.mgr = mgr;
}
public Double getSal() {
return sal;
}
public void setSal(Double sal) {
this.sal = sal;
}
public Date getHiredate() {
return hiredate;
}
public void setHiredate(Date hiredate) {
this.hiredate = hiredate;
}
public Double getComm() {
return comm;
}
public void setComm(Double comm) {
this.comm = comm;
}
public Integer getDeptno() {
return deptno;
}
public void setDeptno(Integer deptno) {
this.deptno = deptno;
}
@Override
public String toString() {
return "Emp{" +
"empno=" + empno +
", ename='" + ename + ''' +
", job='" + job + ''' +
", mgr=" + mgr +
", sal=" + sal +
", hiredate=" + hiredate +
", comm=" + comm +
", deptno=" + deptno +
'}';
}
}
package connectionutil.demo;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class Dbuttil {
private static PreparedStatement pst;
private static ResultSet rst;
public static int remove(Connection conn,String sql,Object...params) throws Exception{
pst = conn.prepareStatement(sql);
for (int i =0;i ids)throws Exception{
Iterator