2 kenlaiisme kenlaiisme 于 2014.07.05 14:27 提问

JSP错误提示Syntax error on token ""\',\'"", delete this token

An error occurred at line: 78 in the jsp file: index.jsp
Syntax error on token ""\',\'"", delete this token

75: Class.forName(dri);
76: con =DriverManager.getConnection(conStr,"test_db","test_pw");
77: stmt = con.createStatement();
78: String sql="insert into table1(userid,username,nickname) values ('" + userid + "','" + username + "','" + nickname + "');";
79: stmt.execute(sql);

语法错误令牌""\',\'"",删除此令牌....

但是我代码里都没有\号,这是哪来的?
难道说,这里的"','"里的单引号'要用转义字符\'才对吗?

1个回答

franzhong
franzhong   2014.07.06 16:23

当然要转义了,不然与insert前面的引号构成一个块,就断掉了,是语法错误
可将String sql='';用单引号就不用转义

Csdn user default icon
上传中...
上传图片
插入图片