<%
String host = "localhost ";
String user = "root ";
String pw = "2 ";
String db = "yu ";
Class. forName ("com. mysql. jdbc. Driver"). newInstance ();
String url = "jdbc: mysql: //" + host + "/" + db;
Connection con = DriverManager. getConnection (url, user, pw );
Statement st = con. createStatement ();
Request. setCharacterEncoding ("gb2312 ");
String username = request. getParameter ("username ");
String password = request. getParameter ("password ");
String SQL = "insert into yuyang values (0, '" + gb2iso (username) + "', '" + gb2iso (password) + "',)";
St.exe cuteUpdate (SQL );
St. close ();
Con. close ();
Response. sendRedirect ("index. jsp ");
%>
Which eldest brother can help the younger brother to see where the SQL statement inserted to the database is wrong.
Why does the following error occur when a migration occurs.
Javax. servlet. ServletException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
Org. apache. jasper. runtime. PageContextImpl. doHandlePageException (PageContextImpl. java: 848)
Org. apache. jasper. runtime. PageContextImpl. handlePageException (PageContextImpl. java: 781)
Org. apache. jsp. login_jsp. _ jspService (org. apache. jsp. login_jsp: 85)
Org. apache. jasper. runtime. HttpJspBase. service (HttpJspBase. java: 97)
Javax. servlet. http. HttpServlet. service (HttpServlet. java: 802)
Org. apache. jasper. servlet. JspServletWrapper. service (JspServletWrapper. java: 322)
Org. apache. jasper. servlet. JspServlet. serviceJspFile (JspServlet. java: 291)
Org. apache. jasper. servlet. JspServlet. service (JspServlet. java: 241)
Javax. servlet. http. HttpServlet. service (HttpServlet. java: 802)
Root cause
Com. mysql. jdbc. exceptions. mySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
Com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 1027)
Com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 957)
Com. mysql. jdbc. MysqlIO. checkErrorPacket (MysqlIO. java: 3376)
Com. mysql. jdbc. MysqlIO. checkErrorPacket (MysqlIO. java: 3308)
Com. mysql. jdbc. MysqlIO. sendCommand (MysqlIO. java: 1837)
Com. mysql. jdbc. MysqlIO. sqlQueryDirect (MysqlIO. java: 1961)
Com.mysql.jdbc.ConnectionImpl.exe cSQL (ConnectionImpl. java: 2537)
Com.mysql.jdbc.StatementImpl.exe cuteUpdate (StatementImpl. java: 1564)
Com.mysql.jdbc.StatementImpl.exe cuteUpdate (StatementImpl. java: 1485)
Org. apache. jsp. login_jsp. _ jspService (org. apache. jsp. login_jsp: 75)
Org. apache. jasper. runtime. HttpJspBase. service (HttpJspBase. java: 97)
Javax. servlet. http. HttpServlet. service (HttpServlet. java: 802)
Org. apache. jasper. servlet. JspServletWrapper. service (JspServletWrapper. java: 322)
Org. apache. jasper. servlet. JspServlet. serviceJspFile (JspServlet. java: 291)
Org. apache. jasper. servlet. JspServlet. service (JspServlet. java: 241)
Javax. servlet. http. HttpServlet. service (HttpServlet. java: 802)
Note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
The data table only has two fields: username and password.