ray
ray

Reputation: 3

How to resolve MySQLSyntaxErrorException exception?

I keep getting MySQLSyntaxErrorException when I create update jsp mysql.

String id_user = request.getParameter("id_login");    
String name_cust = request.getParameter("name_cust");
String password = request.getParameter("password");
String email = request.getParameter("email");
String no_phone = request.getParameter("no_phone");


Statement st = CON.createStatement();
//ResultSet rs;
int i = st.executeUpdate("UPDATE signup SET id_login='"+id_user+"',name_cust='"+name_cust+"', password='"+password+"'email='"+email+"',no_phone='"+no_phone+"', WHERE id_user='"+id_user+"'");

Upvotes: 0

Views: 48

Answers (2)

raju 2192
raju 2192

Reputation: 42

Incorrect syntax in the SQL statement, try this

int i = st.executeUpdate("UPDATE signup SET id_login='"+id_user+"',name_cust='"+name_cust+"', password='"+password+"'email='"+email+"',no_phone='"+no_phone+"'WHERE id_user='"+id_user+"'");

Upvotes: 0

Ravi
Ravi

Reputation: 31417

You have extra , just before WHERE and you are missing one before EMAIL.

"UPDATE signup SET id_login=?, name_cust=?, password=?, email=?, no_phone=? WHERE id_user=?"

Also, you are supposed to use PreparedStatement, to avoid any SQL injection.

Upvotes: 2

Related Questions