あなたはこれは、次の例に
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();
を与えるq-quoted strinグラム例えばq'['''''''']'
を使用することができます。しかし正しい方法は、プリペアドステートメント
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でもバッチ更新を使用できるかどうかはわかりませんでした。 javadocを使い、それができることを理解しました。コメントしてくれてありがとう。! – user1576882