java - for 循环中的 Microsoft SQL Server Prepared 语句不起作用
问题描述
我需要以下帮助。我正在尝试两种方式。两者都没有工作。没有更新行。相同的 sql 可以在没有循环的情况下工作(对于单个字符串)。但我想为多个字符串执行相同的 sql。
方法1:
PreparedStatement pstmt = null;
String query = "UPDATE PeopleTable SET firstname = CAST(REPLACE(CAST(firstname as nvarchar(max)), ? ,'ReplacedFirstName') as ntext)";
pstmt = conn.prepareStatement(query);
for(String s: myList) {
pstmt.setString(1, s);
pstmt.addBatch();
}
pstmt.executeUpdate();
方法:2:
PreparedStatement pstmt = null;
String query = "UPDATE PeopleTable SET firstname = CAST(REPLACE(CAST(firstname as nvarchar(max)), ? ,'ReplacedFirstName') as ntext)";
pstmt = conn.prepareStatement(query);
for(String s: myList) {
pstmt.setString(1, s);
pstmt.executeUpdate();
stmt.clearParameters();
}
两者都不起作用。请帮忙。
解决方案
推荐阅读
- django - Django TextField 不强制执行空白=假
- css - 如何跨对象的多个字段继承样式?
- reactjs - React PDFDownloadLink - 通过代码显式调用 onclick 事件
- python - Python检查元素中键的值并返回列表中的元素
- neo4j - 在(尚未)现有节点之间创建关系
- python - Minmaxscaler inverse_transform 不起作用
- sql - 将特定的sql查询结果组合成一个字符串
- wordpress - 如何为贡献者启用 Wordpress 插件?
- angular - 使用数组映射修改整个对象
- python - 如何在 selenium python 中右键单击并按住它