当前位置: 技术问答>java相关
为何在执行insert 后,数据插入数据库,但是出现以下错误
来源: 互联网 发布时间:2015-01-24
本文导语: 代码如下: String name=request.getParameter("na"); String zt=request.getParameter("zt"); String nr=request.getParameter("nr"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:test","sa",""); Statement s=con.createStatement...
代码如下:
String name=request.getParameter("na");
String zt=request.getParameter("zt");
String nr=request.getParameter("nr");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:test","sa","");
Statement s=con.createStatement(1004,1007) ;
String sql="insert into article (zz,nr,tm) values ('"+name+"','"+zt+"','"+nr+"')";
//response.sendRedirect("www.sohu.com");
ResultSet rs=s.executeQuery(sql);
//ResultSet rs=s.executeQuery("select * from article");
rs.close() ;
con.close() ;
s.close() ;
错误提示:javax.servlet.ServletException: No ResultSet was produced
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
at _0002finsert_00031_0002ejspinsert1_jsp_11._jspService(_0002finsert_00031_0002ejspinsert1_jsp_11.java:85)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
String name=request.getParameter("na");
String zt=request.getParameter("zt");
String nr=request.getParameter("nr");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:test","sa","");
Statement s=con.createStatement(1004,1007) ;
String sql="insert into article (zz,nr,tm) values ('"+name+"','"+zt+"','"+nr+"')";
//response.sendRedirect("www.sohu.com");
ResultSet rs=s.executeQuery(sql);
//ResultSet rs=s.executeQuery("select * from article");
rs.close() ;
con.close() ;
s.close() ;
错误提示:javax.servlet.ServletException: No ResultSet was produced
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
at _0002finsert_00031_0002ejspinsert1_jsp_11._jspService(_0002finsert_00031_0002ejspinsert1_jsp_11.java:85)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
|
你只是进行insert操作,没有记录集返回.
ResultSet rs=s.executeUpdate(sql);改为:
s.executeUpdate(sql)
并删除rs.close() ;
ResultSet rs=s.executeUpdate(sql);改为:
s.executeUpdate(sql)
并删除rs.close() ;