About database insertion

Source: Internet
Author: User

<%
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.