框起来的地方为啥报错?
完整代码:
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;
}
}
你参数是object类型的 你传入的是int类型的, 类型转换错误,改成Integer
【以下回答由 GPT 生成】
我可以解答各种与IT相关的问题,请提供具体的问题描述。
【相关推荐】