Java PreparedStatement setString() adding quotes in query (mysql jdbc) -


this question has answer here:

i'm new in prepared statements, not sure if i'm trying legal or not.

 string updatequery = "update articles set title = ? id in ?";      try{         prestatement = connect.preparestatement(updatequery);          prestatement.setstring(1, "test");         prestatement.setstring(2,"(4,5,6)"); 

i following error:

error: com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: have error in        sql syntax; check manual corresponds mysql server version     right syntax use near ''(4,5,6)'' @ line 1 

it seems setstring() method adding quotes query, there way avoid or method use accomplish i'm trying ?

try this:

final collection<integer> ids = arrays.aslist(4, 5, 6);  final stringbuilder updatequery = new stringbuilder("update articles set title = ? id in (");  (int = 0; < ids.size(); i++) {     updatequery.append("?,"); }  updatequery.deletecharat(updatequery.length() - 1); updatequery.append(")");  system.out.println(updatequery);  prestatement.setstring(1, "test"); int = 2; (final integer id : ids) {     prestatement.setint(i ++, id); } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -