• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PreparedStatement

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm going desperate now and need HELP!
Im trying to do a batchUpdate with a prepared statement:
"INSERT INTO WEB_CLOSET "
+ "(ITEM_CD, MAT_CD, COLOR_CD, SIZE_CD, LOCATION_CD, CUST_ID, LAST_UPDT_DATE) "
+ "(SELECT ?, ?, ?, ?, ?, ?, SYSDATE "
+ "FROM DUAL "
+ "WHERE NOT EXISTS "
+ "(SELECT * FROM WEB_CLOSET W2 "
+ "WHERE W2.ITEM_CD = ? ))"
and:
prepStatement.setString(1, "A");
prepStatement.setString(2, "A");
prepStatement.setString(3, "A");
prepStatement.setString(4, "A");
prepStatement.setString(5, "001" );
prepStatement.setLong(6, 1);
prepStatement.setString(7, "A");
prepStatement.addBatch();
but i can't get parameter 7 to work. This insert should happen if the data is not already there, but not if the data is already in teh database. But i get a
ORA-00001: unique constraint violated
the second time I run it (when the data is already in there)
If i convert parameter 7 and use 1 instead of "A" it works...
Has anyone got any ideas on how to solve this?
// tina
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is ITEM_CD a CHAR rather than a VARCHAR2?
- Peter
 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you set the autocommit to false somewhere?
 
Tina Ljuslin
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
item_cd is a varchar2 and the commit works fine.
I have now solved this by not using a prepared statement, but I still don't understand why it's not working with a prepared statement.
Thanks anyway
// tina
reply
    Bookmark Topic Watch Topic
  • New Topic