public static void updat(String sql,Object...args) throws Exception{
Connection connection=null;
PreparedStatement preparedStatement=null;
try {
connection=getconnetion();
preparedStatement=(PreparedStatement) connection.prepareStatement(sql);
for(int i=0;i<args.length;i++){
preparedStatement.setObject(i+1, args[i]);
}
preparedStatement.executeUpdate();
} catch (ClassNotFoundException e) {

e.printStackTrace();
}

}

-----------------------------------------

测试

@Test
public void test2(){
Student student=new Student();
String sql="insert into users values(?,?,?)";
student.setId(5211314);
student.setNameString("Myongyuan");
student.setSconString("LaiShan");
try {
Tools.updat(sql, student.getId(),student.getNameString(),student.getSconString());
} catch (Exception e) {

e.printStackTrace();
}
}

相关文章:

  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
猜你喜欢
  • 2022-12-23
  • 2021-07-12
  • 2021-08-11
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
  • 2021-07-22
相关资源
相似解决方案