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 the fly likes how to check for insert query? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to check for insert query?" Watch "how to check for insert query?" New topic
Author

how to check for insert query?

duhit Choudhary
Ranch Hand

Joined: Apr 01, 2012
Posts: 64
hi,
i am very new in this topic. through my java code i m trying to execute an insert query and along with this i want to check that the value i am inserting will not get repeat. i.e it will not appear in the table if it is already there and if not then insert the value. this very perplexing for me.
it would be easy and great if somebody explain me through a program. thanks a ton.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

have you heard of database indexes?
if the insert statement is quite simple you could use indexes to prevent duplicate rows, and handle any exceptions.

or you could do a
and if any rows are returned it already exists, i would combine this witha unique index to improve performance.

Notice i am only returning the number 1, this is just to save data being transfered from the db to the java.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to check for insert query?