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.

  1. the table name user reserve word enclose in ""
  2. you checking email. varchar should enclose in '
  3. always try use parameterized sql queries avoid sql injection problem
  4. 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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -