java - Insert and update methods of dao are not working -
for reason adduser()
, updateuser()
methods not working. can 1 please @ code , figure out i'm making mistake.
public void adduser(user user) { try { preparedstatement preparedstatement = connection.preparestatement("insert users(userid, firstname, lastname, jobtitle, email, username, password) values (?,?,?,?,?,?,?)"); // parameters start 1 preparedstatement.setint(1,user.getuserid()); preparedstatement.setstring(2, user.getfirstname()); preparedstatement.setstring(3, user.getlastname()); preparedstatement.setstring(4, user.getjobtitle()); preparedstatement.setstring(5, user.getemail()); preparedstatement.setstring(6, user.getusername()); preparedstatement.setstring(7, user.getpassword()); preparedstatement.executeupdate(); } catch (sqlexception e) { e.printstacktrace(); } } public void updateuser(user user) { try { preparedstatement preparedstatement = connection.preparestatement("update users set email=?, password=? username=?"); preparedstatement.setstring(1, user.getemail()); preparedstatement.setstring(2, user.getusername()); preparedstatement.setstring(3, user.getpassword()); preparedstatement.executeupdate(); } catch (sqlexception e) { e.printstacktrace(); } }
please note don't have experience in java. there no error being printed, why can't tell wrong.
thank in advance.
in updateuser(), order of parameters wrong. sql statement, should email, password , username.
preparedstatement.setstring(1, user.getemail()); preparedstatement.setstring(2, user.getpassword()); preparedstatement.setstring(3, user.getusername());
also, suggest add "finally" block close statement , result set.
Comments
Post a Comment