Operation not allowed after ResultSet closed 如何在一个action中执行多条sql语句

liang896500 2012-12-12 07:26:39
我想在一个action中从两个表中查询数据 写了 两个sql语句 执行的时候 报错 求改代码

package ac;

import com.opensymphony.xwork2.ActionSupport;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import shiti.JxinXin;

public class SplAction extends ActionSupport {
private String name;
private String caption;
private String content;
public List<JxinXin> list;
public List<JxinXin> infolist=new ArrayList<JxinXin>();



public List<JxinXin> getList() {
return list;
}

public void setList(List<JxinXin> list) {
this.list = list;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getCaption() {
return caption;
}

public void setCaption(String caption) {
this.caption = caption;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String execute() throws Exception{
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
String url = "jdbc:mysql://localhost:3306/";
String dbName = "xinxiangfal";
String driverName = "com.mysql.jdbc.Driver";
String userName = "root";
String passWord = "123";

Connection con = null;
Statement stmt = null;
ResultSet rs = null;
ResultSet rst = null;
try {
Class.forName(driverName).newInstance();
con = DriverManager.getConnection(url + dbName, userName, passWord);
stmt = con.createStatement();

} catch (Exception e) {
System.out.println(e.getMessage());
}
String sql = "select * from jshipin where caption='" + this.name + "'";
String sqlt="select * from sinfor where jid=(select jid from jshipin where caption='"+this.name+"');";
rs = stmt.executeQuery(sql);



while(rs.next()){
caption=rs.getString("caption");
content=rs.getString("content");
session.put("TZ", this.name);



}
rst= stmt.executeQuery(sqlt);
rs.last();

while(rst.next()){

JxinXin jx=new JxinXin();
jx.setSid(rst.getInt("sid"));
jx.setFileName(rst.getString("fileName"));
jx.setTime(rst.getString("time"));
}
this.setList(infolist);


return SUCCESS;


}

}
提示的错误是 Operation not allowed after ResultSet closed 该如何执行啊 谢谢大家
...全文
133 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
liang896500 2012-12-13
  • 打赏
  • 举报
回复
好吧 我谢谢你们 我知道哪里错了 已经改过来了 谢谢
licip 2012-12-12
  • 打赏
  • 举报
回复
你要把错误的信息全贴出来。才好判断错是出在哪里。
NoTargetException 2012-12-12
  • 打赏
  • 举报
回复
代码格式这样子都不想看。 看错误估计就是:数据集已经关闭了,所以不能再操作了。 你断点一下就知道哪里出错

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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