主题:关于数据库插入的问题
<%
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.executeUpdate(sql);
st.close();
con.close();
response.sendRedirect("index.jsp");
%>
哪位大哥可以帮帮小弟看看这上面的插入数据库的SQL语句哪里错了啊。
为什么一运行就出现以下错误的.
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.execSQL(ConnectionImpl.java:2537)
com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564)
com.mysql.jdbc.StatementImpl.executeUpdate(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.
数据表里只有两field 分别是username和password
哪位大哥帮帮小弟改改啊。谢谢了!!!
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.executeUpdate(sql);
st.close();
con.close();
response.sendRedirect("index.jsp");
%>
哪位大哥可以帮帮小弟看看这上面的插入数据库的SQL语句哪里错了啊。
为什么一运行就出现以下错误的.
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.execSQL(ConnectionImpl.java:2537)
com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564)
com.mysql.jdbc.StatementImpl.executeUpdate(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.
数据表里只有两field 分别是username和password
哪位大哥帮帮小弟改改啊。谢谢了!!!