I am trying to update values in my SQLite Database. My code is as follows:
for(Cookie ck:cookie) {
if (ck.getName().equals("email")) {
s=ck.getValue();
System.out.println(s);
for(Cookie ce:cookie) {
if(ce.getName().equals("name")) {
System.out.println(ce.getValue());
i=PS.executeUpdate("UPDATE Details "+"SET name="+ce.getValue()+" WHERE email="+s);
}
else if (ce.getName().equals("age")) {
System.out.println(ce.getValue());
i=PS.executeUpdate("UPDATE Details "+"SET age="+ce.getValue()+" WHERE email="+s);
}
}
break;
}
}
Here, I am trying to fetch the name , age and email with the help of Cookies
and updating those values in the database. Then when I enter the inputs, I get this error (suppose the email is: abc@gmail.com ):
java.sql.SQLException: near "@gmail": syntax error
at org.sqlite.NativeDB.throwex(NativeDB.java:210)
at org.sqlite.NativeDB._exec(Native Method)
at org.sqlite.Stmt.executeUpdate(Stmt.java:152)
at abhishek.Modify.doGet(Modify.java:44)...
You have to add single quotes around strings in sql.
i=PS.executeUpdate("UPDATE Details "+"SET name='"+ce.getValue()+"' WHERE email='"+s+"'");
...
i=PS.executeUpdate("UPDATE Details "+"SET age="+ce.getValue()+" WHERE email='"+s+"'")
BTW learn about prepared statements to prevent sql-injection
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.