I am saving date logs every time a user logs in. Date logs will save a date in the record, but what I want is for there to be no duplicates. It will check if the record is already existing, and if yes it will not save the date. If the record does not yet exist it will save the date.
Here is my code:
SimpleDateFormat dnow2 = new SimpleDateFormat("MMMMM dd, yyyy");
ResultSet ds = MyDB.rsFetch("SELECT * FROM `date-logs` WHERE `Date` = '"+dnow.format(new java.util.Date())+"'");
try {
ds.next() ;
if (ds.getMetaData().getColumnCount() == 0) {
MyDB.exSQL( "INSERT INTO `date-logs` (`Date Code`, `Date`) "
+ "VALUES ('"+dnow.format(new java.util.Date())+ "',"
+ "'"+dnow2.format(new java.util.Date())+"')");
}
} catch (SQLException ex) {
Logger.getLogger(FrmLogIn.class.getName()).log(Level.SEVERE, null, ex);
}