java - JDBC and Oracle DB : Escape ' (single quote) -
hello looks simple having issues here.
firstly using statement#executebatch executing many update statements. each update statements have string value updated. these string have " ' " single quote. have tried adding 1 more single quote in front of per oracle doc adding '\\\' in front of single quote. first one, query gets stuck , not come out after 10 minutes. second 1 'batching: ora-00927: missing equal sign' error.
what correct approach? note:- cannot use preparedstatement make use of jdbc parameters.
please help.
you may use q-quoted string eg q'['''''''']'
this give following example
statement stmt = con.createstatement(); stmt.addbatch("update tst set txt = q'['''''''']' id = 1"); stmt.addbatch("update tst set txt = q'['''''''']' id = 2"); stmt.addbatch("update tst set txt = q'['''''''']' id = 3"); stmt.addbatch("update tst set txt = q'['''''''']' id = 4"); stmt.addbatch("update tst set txt = q'['''''''']' id = 5"); // submit batch of update commands execution int[] updatecounts = stmt.executebatch();
but correct way use prepared statement
preparedstatement stmt = con.preparestatement("update tst set txt = ? id = ?"); 5.times { -> stmt.setstring(1, "''''''''"); stmt.setint(2, i+1); stmt.addbatch(); } // submit batch of update commands execution int[] updatecounts = stmt.executebatch();
Comments
Post a Comment