public static void update(String sql,Object... args){
Connection conn=null;
PreparedStatement ps=null;
try {
Driver driver =new Driver();
String url="jdbc:mysql://localhost:3306/test?useSSL=false";
Properties info=new Properties();
info.setProperty("user","root");
info.setProperty("password","XXXXXX");
conn = driver.connect(url, info);
ps=conn.prepareStatement(sql);
for (int i = 0; i < args.length; i++) {
ps.setObject(i+1,args[i]);
}
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
**数据库查询的时候使用 executeQuery()
数据库插入的时候使用 executeUpdate()**
java.sql.SQLException: Can not issue data manipulation statements with executeQuery()错误
最新推荐文章于 2021-09-02 19:47:14 发布