Java JDBC和oracledb:Escape';(单引号)

Java JDBC和oracledb:Escape';(单引号),java,jdbc,escaping,quote,Java,Jdbc,Escaping,Quote,您好,这看起来很简单,但我这里有问题 首先,我使用它来执行许多UPDATE语句。每个update语句都有要更新的字符串值。这些字符串有“'”单引号。我曾尝试根据Oracle文档在其前面添加一个单引号,并在单引号前面添加“\\\”。对于第一个问题,我的查询被卡住了,即使在10分钟后也不会出来。第二个错误是“批处理:ORA-00927:缺少等号”错误 什么是正确的方法? 注意:-我不能使用PreparedStatement来使用JDBC参数 请帮助。您可以使用g egq'[''''''] 下面给出一

您好,这看起来很简单,但我这里有问题

首先,我使用它来执行许多UPDATE语句。每个update语句都有要更新的字符串值。这些字符串有“'”单引号。我曾尝试根据Oracle文档在其前面添加一个单引号,并在单引号前面添加“\\\”。对于第一个问题,我的查询被卡住了,即使在10分钟后也不会出来。第二个错误是“批处理:ORA-00927:缺少等号”错误

什么是正确的方法? 注意:-我不能使用PreparedStatement来使用JDBC参数

请帮助。

您可以使用g eg
q'['''''']

下面给出一个例子

Statement stmt = con.createStatement();

stmt.addBatch("update tst set txt = q'['''''''']' where id = 1");
stmt.addBatch("update tst set txt = q'['''''''']' where id = 2");
stmt.addBatch("update tst set txt = q'['''''''']' where id = 3");
stmt.addBatch("update tst set txt = q'['''''''']' where id = 4");
stmt.addBatch("update tst set txt = q'['''''''']' where id = 5"); 
// submit a batch of update commands for execution
int[] updateCounts = stmt.executeBatch();
但正确的方法是使用事先准备好的语句

PreparedStatement stmt = con.prepareStatement("update tst set txt = ? where id = ?");
5.times { i ->
  stmt.setString(1, "''''''''");
  stmt.setInt(2, i+1);
  stmt.addBatch();
}

// submit a batch of update commands for execution
int[] updateCounts = stmt.executeBatch();
您可以使用g eg
q'[''']'

下面给出一个例子

Statement stmt = con.createStatement();

stmt.addBatch("update tst set txt = q'['''''''']' where id = 1");
stmt.addBatch("update tst set txt = q'['''''''']' where id = 2");
stmt.addBatch("update tst set txt = q'['''''''']' where id = 3");
stmt.addBatch("update tst set txt = q'['''''''']' where id = 4");
stmt.addBatch("update tst set txt = q'['''''''']' where id = 5"); 
// submit a batch of update commands for execution
int[] updateCounts = stmt.executeBatch();
但正确的方法是使用事先准备好的语句

PreparedStatement stmt = con.prepareStatement("update tst set txt = ? where id = ?");
5.times { i ->
  stmt.setString(1, "''''''''");
  stmt.setInt(2, i+1);
  stmt.addBatch();
}

// submit a batch of update commands for execution
int[] updateCounts = stmt.executeBatch();

请详细说明为什么不能使用PreparedStatements。尝试手动生成和转义sql会使您容易受到应用程序错误和sql注入攻击。我不知道即使使用PreparedStatement也可以使用batch update。通过javadoc了解到它是可以做到的。谢谢你的评论。!请详细说明为什么不能使用PreparedStatements。尝试手动生成和转义sql会使您容易受到应用程序错误和sql注入攻击。我不知道即使使用PreparedStatement也可以使用batch update。通过javadoc了解到它是可以做到的。谢谢你的评论。!我不知道我可以使用批处理更新,即使是PreparedStatement。通过javadoc了解到它是可以做到的。谢谢你的评论。!我不知道我可以使用批处理更新,即使是PreparedStatement。通过javadoc了解到它是可以做到的。谢谢你的评论。!