Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Insert or Update using prepared statement in java

 
seena mathew
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am a newbee in Java.
What I want to do in my program is to
1) insert a new row in case the row doesn't exist OR
2) Update the row if the row exists

I checked the api and didn't find anything
 
Paul Clapham
Sheriff
Posts: 21955
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pseudocode:

Unless of course your database has an "UPDATE-IF-ROW-EXISTS-ELSE-INSERT" command in its version of SQL. (Most of them don't.) But this would be a question about your database, rather than about JDBC.
 
Sudheer Bhat
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using Oracle as your DB, you can use MERGE statement.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!