java - How to UPDATE a column using a variable? -


i have 2 questions:

1) how can call variable inside update query because want use same line update lots of columns. did in insert , select, cause error in update used where:

string x="term";  try{      connection con = drivermanager.getconnection("jdbc:mysql://localhost/ourproject?useunicode=true&characterencoding=utf8&user=luffy&password=111111");     statement stmt=(statement) con.createstatement();     string select = "select ('" + x  + "') test doc=0";      stmt.executeupdate(select);    }    catch(exception e)    {     e.printstacktrace();       } 

2) if call variable, how can update value adding 1? tried , worked:

try{      connection con = drivermanager.getconnection("jdbc:mysql://localhost/ourproject?useunicode=true&characterencoding=utf8&user=luffy&password=111111");     statement stmt=(statement) con.createstatement();     string update = "update test set term=term+1 doc=0";      preparedstatement updatequey =con.preparestatement(update);     updatequery.executeupdate(update);    }    catch(exception e)    {     e.printstacktrace();       } 

but need call x , because want use same line more 1 column. thankx in advance

you can use prepared statements parameters. here docu oracle it.

in context:

string update = "update test set term = ? doc=0";  preparedstatement updatequey = con.preparestatement(update); updatequey.setint(1, x); updatequery.executeupdate(); 

btw: don't think need update string parameter of executeupdate()


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -