Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting batch updation exception.

 
Jack Nicholson
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
While adding batch for updation i am getting strange exception can any body tell me what to do in this case?
I am using prepareStatement for this case.
--
psmt=con.prepareStatement("?");
psmt.setString(1,SBf.toString());
addBatch()
Error is like this when i try to execute executeBatch()
---------------------------
Query built->insert into kemp (EMPNO, ENAME, SAL) values (13,'Try1',1000)
Batch Added
Query built->insert into kemp (EMPNO, ENAME, SAL) values (13,'Try2',1000)
Batch Added
java.sql.BatchUpdateException: ORA-00900: invalid SQL statement
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
at TestUtility.elxUpdate(TestUtility.java:132)
at TestUtility.init(TestUtility.java:73)
at TestUtility.<init>(TestUtility.java:43)
at TestUtility.main(TestUtility.java:38)
At end of init()
---------------------------
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many things wrong when you evaluate what is actually being executed, but it all comes down to the fact that you are abusing the prepared statement. Prepared statements are to be used if you are repeatedly using the same SQL statement, except only the parameter values are changing in the where clause (which are represented by a ? ). You need to use a Statement object to accomplish your goal, or prepareStatement() for each different query.
Solution 1

Solution2

OR something similar to this.
Jamie
 
Jack Nicholson
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Jamie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic