java - I cannot update my Date column? error: datatruncation -
mysql datatype column "logindate" date. why error?
private void comparedate(){ sql = "select curdate()"; date currentdate = lastlogin; try{ ps = con.preparestatement(sql); rs = ps.executequery(); while(rs.next()){ currentdate = rs.getdate(1); } }catch(sqlexception e){ system.out.println(e); } if(currentdate.compareto(lastlogin) == 1){ system.out.println(currentdate); system.out.println(lastlogin); sql = "update customers set logindate="+currentdate+", nflixcredit=3 username='"+username+"'"; try{ ps = con.preparestatement(sql); ps.executeupdate(); }catch(sqlexception e){ system.out.println(e); } } } 2015-05-30
2015-05-29
error -
com.mysql.jdbc.mysqldatatruncation: data truncation: incorrect date value: '1980' column 'logindate' @ row 1
what using not prepared statement.
change to
sql = "update customers set logindate=?, nflixcredit=3 username=?"; try{ ps = con.preparestatement(sql); ps.setdate(1,currentdate); ps.setstring(2,username); ps.executeupdate(); }catch(sqlexception e){ in case tostring() method of date called , date long
Comments
Post a Comment