MySQL: Check if I want to insert an already existing value using JAVA -


i have table column want insert data not existing data.

to give example have day column , customer. same customer cannot have same date twice, have customer named karl , on monday. if try add karl monday, when existing on monday, should not that. how do this? assuming using jtextfields type name , day.

so far got insert data works (though without checking if it's existing!)

s.executequery ("select * customer"); s.executeupdate("insert customer values ('"+name.gettext()+"', '"+day.gettext()+"')"); 

how check if type in name textfield , day textfield both exist in same row?

thanks in advance

try this

preparedstatement s = connection.preparestatement("select * customer name=? , date=?"); s.setstring(1, name.gettext()); s.setstring(2, day.gettext()); resultset result = s.executequery (); if(result.next()) {     // dupilcate records present. don't add } else {     // add records table.     s.executeupdate("insert customer values ('"+name.gettext()+"', '"+day.gettext()+"')"); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -