/**
* 针对不同表的通用增删改操作
*/
public static void update(String sql, Object... args) {
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
//1.获取连接
connection = JDBCUtils.getConnection();
//2.预编译语句
preparedStatement = connection.prepareStatement(sql);
for (int i = 0; i < args.length; i++) {
//the first parameterIndex is 1, the second is 2, ...
preparedStatement.setObject(i+1, args[i]);
}
//3.执行
preparedStatement.execute();
} catch (Exception e) {
e.printStackTrace();
} finally {
//4.释放资源
JDBCUtils.closeResource(connection, preparedStatement);
}
}