我试图通过创建新语句来执行多个查询,但是它没有对数据库进行任何更改。
代码如下:
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb?verifyServerCertificate=false&useSSL=true","root","root");
Statement st = con.createStatement();
Statement st1=con.createStatement();
ResultSet rs = st.executeQuery("select emp_id from emp_details where seat_num="+seat_num);
ResultSet rs1 = st1.executeQuery("select max(id) from complaints");
String num = rs1.getString(1);
// System.out.println(num);
String emp_id = null;
if(rs.next()){
emp_id = rs.getString(1);
stmt = con.prepareStatement("INSERT INTO mydb.complaints(emp_id,type,description,id,seat_num) VALUES (?,?,?,?,?)");
stmt.setInt(1,Integer.parseInt(emp_id) );
stmt.setString(2, type);
stmt.setString(3, description);
stmt.setInt(5,Integer.parseInt(seat_num));
stmt.setInt(4,Integer.parseInt(num)+1);
stmt.execute();
con.close();