框起来的地方为啥报错?
完整代码:
public class PSCURDPart extends BaseDao{
@Test
public void testInsert() throws ClassNotFoundException, SQLException {
String sql = "insert into employee(id, salary) values(?, ?);";
int rows = executeUpdate(sql, 1, 111);
}
}
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects;
public class BaseDao {
public int executeUpdate(String sql, Objects... params) throws Exception {//可变参数必须存在于形参列表的最后一位
Connection connection = JdbcUtilsV2.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql);
for (int i = 1; i <= params.length; i++) {
preparedStatement.setObject(i, params[i]);
}
int rows = preparedStatement.executeUpdate();
preparedStatement.close();
if (connection.getAutoCommit()) {
JdbcUtilsV2.freeConnection();
}
return rows;
}
}