<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<body>
<%@ include file="connection.jsp" %>
<% String id=request.getParameter("id");
String name=request.getParameter("name");
// byte n[]=name.getBytes("iso-8859-1");
// name=new String(n);
String sex=request.getParameter("sex");
//byte s[]=sex.getBytes("iso-8859-1");
//sex=new String(s);
String value="values('"+id+"','"+name+"','"+sex+"')";
String sql="insert into student "+value;
ResultSet rs= stmt.executeQuery(sql);
%>
</body>
</html>
一直在报错!!!!!!
org.apache.jasper.JasperException: Exception in JSP: /chen/insert.jsp:19
16:
17: String value="values('"+id+"','"+name+"','"+sex+"')";
18: String sql="insert into student "+value;
19: ResultSet rs= stmt.executeQuery(sql);
20:
21:
22: %>
sql到底错在那里???????
----------------解决方案--------------------------------------------------------
有异常情况,应该还有更基本的异常,你帖出来看看
----------------解决方案--------------------------------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ include file="connection.jsp" %>
<head>
<title>添加学生信息</title>
</head>
<h1 align="center">简易学生信息管理系统</h1>
<hr />
<br />
<br />
<body bgcolor="cyan">
<form action="add.jsp" method="get">
<table border="1" width="500" align="center">
<tr>
<th >学号:</th><td align="center"><input type="text" name="id" size="20" /></td>
</tr>
<tr>
<th >姓名:</th><td align="center"><input type="text" name="name" size="20" /></td>
</tr>
<tr>
<th>性别:</th><td align="center"><input type="text" name="sex" size="20" /></td>
</tr>
<tr>
<td colspan="2" align="center"> <input type="submit" value="提交" /></td>
</tr>
</table>
</form>
<% String id=request.getParameter("id");
String name=request.getParameter("name");
// byte n[]=name.getBytes("iso-8859-1");
// name=new String(n);
String sex=request.getParameter("sex");
//byte s[]=sex.getBytes("iso-8859-1");
//sex=new String(s);
String value="values('"+id+"','"+name+"','"+sex+"')";
String sql="insert into student "+value;
ResultSet rs= stmt.executeQuery(sql);
%>
</body>
<%@ include file="info.jsp"%>
</html>
----------------解决方案--------------------------------------------------------
上边是源码,tomcat报错如下:
org.apache.jasper.JasperException: Exception in JSP: /chen/add.jsp:43
40:
41: String value="values('"+id+"','"+name+"','"+sex+"')";
42: String sql="insert into student "+value;
43: ResultSet rs= stmt.executeQuery(sql);
44:
45:
46: %>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: Can not issue data manipulation statements with executeQuery().
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.chen.add_jsp._jspService(add_jsp.java:121)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
com.mysql.jdbc.Statement.checkForDml(Statement.java:305)
com.mysql.jdbc.Statement.executeQuery(Statement.java:885)
org.apache.jsp.chen.add_jsp._jspService(add_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
----------------解决方案--------------------------------------------------------
javax.servlet.ServletException: Can not issue data manipulation statements with executeQuery().
你的插入操作,怎么能executeQuery呢,应该是executeUpdate()
----------------解决方案--------------------------------------------------------
谢谢。弱智性错误!
----------------解决方案--------------------------------------------------------