File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and Relational Databases and the fly likes Is there any function like saveOrUpdate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Is there any function like saveOrUpdate" Watch "Is there any function like saveOrUpdate" New topic
Author

Is there any function like saveOrUpdate

Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 112
Hi All,
I just wanted to know if there is any function in JDBC which could do saveOrUpdate based on the existence of a primary key i.e if a primary key for the object to be inserted exists in db then it should update that record otherwise insert the record.


Regards, Fawad Ali.
Software Engineer, Stafona Inc. - My Blog
Sam Falzon
Greenhorn

Joined: Apr 29, 2011
Posts: 5

What database and which version are you using? If you are using Oracle, look into the MERGE comand.
Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 112
I am using mySql server...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 19357
    
  10

I googled for "mysql update or insert". From that I found that many people had asked that question on the MySQL forum, and Google kindly provided me with links to those questions. I just chose the first link, and noticed that the first answer on that forum was this:

http://dev.mysql.com/doc/refman/5.0/en/replace.html

In other words, the answer to your question is... Yes.
Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 112
Thanks Paul. It helped.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there any function like saveOrUpdate