一个小问题,在线等(statement)

yyqllxh2004 2004-07-26 07:56:06
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
<title>注册确认</title>
<link rel=stylesheet href="bbs.css" type="text/css">
</head>
<body>
<Br><br><br>
<center>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<% Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://192.168.1.61/AddrBook_database?user=heyi&password=123&useUnicode=true&characterEncoding=8859_1";
Connection conn= DriverManager.getConnection(url);
//取值
String username=request.getParameter("username");
username= new String(username.getBytes("ISO8859-1"),"GBK");
session.putValue("register_message",username);
String status=request.getParameter("status");
String password=request.getParameter("password");
//已经声明的变量不能再声明
long miliSeconds = Calendar.getInstance().getTimeInMillis();
long nowtime=miliSeconds/1000;
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stmt1=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql1="select max(UserID) from IM_Users";
out.println(sql1);
ResultSet rs1=stmt.executeQuery(sql1);
int UserID1;
int UserID;
int rownum;
rs1.last();//记录集指针放到最后一行
rownum=rs1.getRow();//取记录数
if (rownum==0){//rs1如果为空不能取东西,不然有错
UserID1=1;
}else{
UserID=rs1.getInt(1);
UserID1=UserID+1;
}
String sql="insert into IM_Users(UserID,UserName,Password,HA1,Status,SipUrl,CreateTime) values('"+UserID1+"','"+username+"','"+password+"','"+password+"','"+status+"','"+username+"','"+nowtime+"')";
out.println(sql);
ResultSet rs=stmt1.executeQuery(sql);
rs.close();
rs1.close();
stmt.close();
stmt1.close();
conn.close();
response.sendRedirect("regok.jsp?username="+username+"");
%>


执行后为什么会出现下面的错误:javax.servlet.ServletException: Can not issue data manipulation statements with executeQuery()
我已经建了两个statement啊?请教


...全文
96 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyqllxh2004 2004-07-27
  • 打赏
  • 举报
回复
是stmt1.executeUpdate(sql);
fanqingfeng 2004-07-27
  • 打赏
  • 举报
回复
汗 谢谢
yyqllxh2004 2004-07-26
  • 打赏
  • 举报
回复
哈哈自己已经解决,不用声明rs,此处
ResultSet rs=stmt1.executeQuery(sql); 《《《
stmt1.executeQuery(sql); 即可

还是谢谢 fanqingfeng(丰丰),给分
yyqllxh2004 2004-07-26
  • 打赏
  • 举报
回复
Incompatible type for declaration. Can't convert boolean to java.sql.ResultSet.
ResultSet rs=stmt1.execute(sql);
现在是这个错误了。
谁遇到过啊?
fanqingfeng 2004-07-26
  • 打赏
  • 举报
回复
插入 修改 删除都用execute(sql);
fanqingfeng 2004-07-26
  • 打赏
  • 举报
回复
String sql="insert into IM_Users(UserID,UserName,Password,HA1,Status,SipUrl,CreateTime) values('"+UserID1+"','"+username+"','"+password+"','"+password+"','"+status+"','"+username+"','"+nowtime+"')";
out.println(sql);
ResultSet rs=stmt1.executeQuery(sql); 《《《
查询用executeQuery(sql); 插入用execute(sql);
yyqllxh2004 2004-07-26
  • 打赏
  • 举报
回复
执行到ResultSet rs=stmt1.executeQuery(sql);这一句就出上面的问题啊???
fanqingfeng 2004-07-26
  • 打赏
  • 举报
回复
rs.close();
stmt1.close();

rs1.close();
stmt.close();
conn.close();


因为你上面
rs1=stmt.executeQuery(sql);
rs=stmt1.executeQuery(sql);
fanqingfeng 2004-07-26
  • 打赏
  • 举报
回复
不好意思 对错位置了
fanqingfeng 2004-07-26
  • 打赏
  • 举报
回复

rs1.close();
stmt1.close();

rs.close();
stmt.close();
conn.close();
yyqllxh2004 2004-07-26
  • 打赏
  • 举报
回复
rs.close();
rs1.close();
stmt1.close();
stmt.close();
conn.close();
改了还是同样的啊??
fanqingfeng 2004-07-26
  • 打赏
  • 举报
回复
rs 先close 才 stmt close
yyqllxh2004 2004-07-26
  • 打赏
  • 举报
回复
stmt1.close();
rs1.close();
stmt.close();
rs.close();
已经倒过来了,还是不行,同样错误啊???
fanqingfeng 2004-07-26
  • 打赏
  • 举报
回复
stmt.close();
stmt1.close();

关闭的顺序位置倒过来
stmt1.close();
stmt.close();

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧