Class.forName("com.ibm.db2.jcc.DB2Driver");
Connectioncon=DriverManager.getConnection("jdbc:db2://localhost:50000/TEST","db2admin","db2admin");
Statement stmt=con.createStatement();
String v=request.getParameter("val");
String query="insert into value values('"+v+"')";
stmt.executeUpdate(query);
stmt.close();
con.close();
我收到一条错误消息,说服务器在处理executeUpdate()命令时遇到错误。似乎无法弄清楚问题。我正在使用IBM DB2。请帮忙......
在这里,这是我一直遇到的错误
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /check.jsp at line 26
23: String read = "insert into `value` values(?)";
24: PreparedStatement p = (PreparedStatement) con.prepareStatement(read);
25: p.setString(1, request.getParameter("val"));
26: p.executeUpdate();
27: p.close();
28: con.close();
29: out.println("Everything done...");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:456)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
javax.servlet.ServletException: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-7, SQLSTATE=42601, SQLERRMC=`;insert into , DRIVER=3.62.56
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.check_jsp._jspService(check_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-7, SQLSTATE=42601, SQLERRMC=`;insert into , DRIVER=3.62.56
com.ibm.db2.jcc.am.fd.a(fd.java:676)
com.ibm.db2.jcc.am.fd.a(fd.java:60)
com.ibm.db2.jcc.am.fd.a(fd.java:127)
com.ibm.db2.jcc.am.jn.c(jn.java:2614)
com.ibm.db2.jcc.am.jn.d(jn.java:2602)
com.ibm.db2.jcc.am.jn.a(jn.java:2094)
com.ibm.db2.jcc.am.kn.a(kn.java:6720)
com.ibm.db2.jcc.t4.cb.g(cb.java:141)
com.ibm.db2.jcc.t4.cb.a(cb.java:41)
com.ibm.db2.jcc.t4.q.a(q.java:32)
com.ibm.db2.jcc.t4.rb.i(rb.java:135)
com.ibm.db2.jcc.am.jn.gb(jn.java:2064)
com.ibm.db2.jcc.am.kn.pc(kn.java:3214)
com.ibm.db2.jcc.am.kn.b(kn.java:3999)
com.ibm.db2.jcc.am.kn.dc(kn.java:746)
com.ibm.db2.jcc.am.kn.executeUpdate(kn.java:729)
org.apache.jsp.check_jsp._jspService(check_jsp.java:85)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
答案 0 :(得分:0)
您是否尝试过编码该值并查看其是否有效?您是否尝试直接在数据库上执行sql语句以确保您具有正确的语法? 请参阅下面的安全插入示例。
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = (Connection) DriverManager.getConnection(DBurl, user, password);
String read = "insert into `value` values(?)";
PreparedStatement p = (PreparedStatement) con.prepareStatement(read);
p.setString(1, request.getParameter("val"));
p.executeUpdate();
答案 1 :(得分:0)
如果您尝试插入的数据类型是BIGINT,则p.setString
将不起作用,因为setString用于设置字符数据类型。
你必须使用
p.setLong(1, request.getParameter("val"));
请参阅文档here