我有一个带有3个参数的java.sql.CallableStatement,我需要多次调用它,为第三个参数传递不同的值。多次使用`java.sql.CallableStatement`而不关闭它
这样做的正确方法是什么?我可以每次创建一个新的可调用语句,但据我所知它可以访问数据库。
当前代码通过更改第三个参数来调用同一个语句实例,但没有关闭它并且似乎可以工作。跳过关闭可调用语句是否正常?
它在MySQL jdbc连接上运行。
代码片段:
CallableStatement pivot = connection.prepareCall("{CALL pivot(?, ?, ?)]");
pivot.setString(1, "a");
pivot.setString(2, "b");
while(someCondition) {
pivot.setString(3, "c");
ResultSet res = pivot.executeQuery();
try {
// ...
} finally {
res.close();
}
}