| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 893 人关注过本帖
标题:insert 错在那里?
只看楼主 加入收藏
fengxfu
Rank: 1
等 级:新手上路
帖 子:180
专家分:0
注 册:2006-7-22
收藏
 问题点数:0 回复次数:5 
insert 错在那里?

<%@ 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到底错在那里???????

搜索更多相关主题的帖子: insert String java name 
2007-07-27 20:32
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
有异常情况,应该还有更基本的异常,你帖出来看看


可惜不是你,陪我到最后
2007-07-27 20:40
fengxfu
Rank: 1
等 级:新手上路
帖 子:180
专家分:0
注 册:2006-7-22
收藏
得分:0 

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


我靠~~问题多得很!
2007-07-27 20:57
fengxfu
Rank: 1
等 级:新手上路
帖 子:180
专家分:0
注 册:2006-7-22
收藏
得分:0 

上边是源码,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)


我靠~~问题多得很!
2007-07-27 20:58
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
javax.servlet.ServletException: Can not issue data manipulation statements with executeQuery().


你的插入操作,怎么能executeQuery呢,应该是executeUpdate()

可惜不是你,陪我到最后
2007-07-27 21:29
fengxfu
Rank: 1
等 级:新手上路
帖 子:180
专家分:0
注 册:2006-7-22
收藏
得分:0 

谢谢。弱智性错误!


我靠~~问题多得很!
2007-07-27 23:03
快速回复:insert 错在那里?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031233 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved