日期:2014-05-19  浏览次数:20807 次

Operation not allowed after ResultSet closed 如何在一个action中执行多条sql语句
我想在一个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    该如何执行啊&n