SQL - Java - UPDATE statement query -
so want "update 'usertype' column in 'user' table where email(/user) value obtained textbox"
jbutton grantbutton = new jbutton("grant seller access"); grantbutton.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) { try { string update_query = "update user set usertype = 'seller' email = " & grantfield.gettext()";" //here error stated on eclipse preparedstatement pst = connect.preparestatement(update_query); pst.setstring(1, grantfield.gettext()); pst.execute(); joptionpane.showmessagedialog(null, "the request has been approved"); } catch (exception e) { e.printstacktrace(); } } }); is possible this?
any appreciated.
there problem sql query.
- the table name
userreserve word enclose in "" - you checking email. varchar should enclose in
' - always try use parameterized sql queries avoid sql injection problem
you doing setstring pass value query in query not specifying value should substituted.
string update_query ="update "user" set usertype = 'seller' email = '" & grantfield.gettext()&"';" preparedstatement pst = connect.preparestatement(update_query); //pst.setstring(1, grantfield.gettext()); statement not needed because providing value in query iteself pst.execute();
or
string update_query = "update [user] set usertype = 'seller' email = ?" ; preparedstatement pst = dbconnection.preparestatement(update_query); pst.setstring(1,grantfield.gettext()); pst.execute();
Comments
Post a Comment