java.sql.SQLException: Operation not allowed after ResultSet closed
意思是说你的结果集关闭之后不允许操作,应该是你的dbXline类里面的代码有问题,页面代码没看除错误。可以的话发你的dbXline类来看看!
意思是说你的结果集关闭之后不允许操作,应该是你的dbXline类里面的代码有问题,页面代码没看除错误。可以的话发你的dbXline类来看看!
getConn();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from xline " + where);
return rs;
}
package import java.sql.*;public class dbXline extends dbBase{
private long id;
private Timestamp t;
private long userid;
private String username;
private String type;
private double cash;
private double credit;
private double cashbalance;
private double creditbalance;
private String note;
private String accountname;
private String place;
private long agentid;
private String agentname;
private double returnleft;
private long aim;
private String sign;
private long cycle;
private double turnma;
private double tmsying;
private double fchsying;
private double cmshu;
public dbXline() {
} public void setId(long id) {
this.id = id;
} public void setT(Timestamp t) {
this.t = t;
} public void setUserid(long userid) {
this.userid = userid;
} public void setUsername(String username) {
this.username = username;
} public void setType(String type) {
this.type = type;
} public void setCash(double cash) {
this.cash = cash;
} public void setCredit(double credit) {
this.credit = credit;
} public void setCashbalance(double cashbalance) {
this.cashbalance = cashbalance;
} public void setCreditbalance(double creditbalance) {
this.creditbalance = creditbalance;
} public void setNote(String note) {
this.note = note;
} public void setAccountname(String accountname) {
this.accountname = accountname;
} public void setPlace(String place) {
this.place = place;
} public void setAgentid(long agentid) {
this.agentid = agentid;
} public void setAgentname(String agentname) {
this.agentname = agentname;
}
public void setReturnleft(double returnleft) {
this.returnleft = returnleft;
}
public void setAim(long aim) {
this.aim = aim;
}
public void setSign(String sign) {
this.sign = sign;
}
public void setCycle(long cycle) {
this.cycle = cycle;
}
public void setTurnma(double turnma) {
this.turnma = turnma;
}
public void setTmsying(double tmsying) {
this.tmsying = tmsying;
}
public void setFchsying(double fchsying) {
this.fchsying = fchsying;
}
public void setCmshu(double cmshu) {
this.cmshu = cmshu;
}
public long getId() {
return id;
} public Timestamp getT() {
return t;
} public long getUserid() {
return userid;
} public String getUsername() {
return username;
} public String getType() {
return type;
} public double getCash() {
return cash;
} public double getCredit() {
return credit;
} public double getCashbalance() {
return cashbalance;
} public double getCreditbalance() {
return creditbalance;
} public String getNote() {
return note;
} public String getAccountname() {
return accountname;
} public String getPlace() {
return place;
} public long getAgentid() {
} public String getAgentname() {
return agentname;
}
public double getReturnleft() {
return returnleft;
}
public long getAim() {
return aim;
}
public String getSign() {
return sign;
}
public long getCycle() {
return cycle;
}
public double getTurnma() {
return turnma;
}
public double getTmsying() {
return tmsying;
}
public double getFchsying() {
return fchsying;
}
public double getCmshu() {
return cmshu;
}
public boolean lookup(long lineid)throws SQLException{
getConn();
try{
PreparedStatement ps = conn.prepareStatement("select * from xline where id=?");
ps.setLong(1,lineid);
ResultSet rs=ps.executeQuery();
if(rs.next()){
id=rs.getLong("id");
t=rs.getTimestamp("t");
userid=rs.getLong("userid");
username=rs.getString("username");
type=rs.getString("type");
cash=rs.getDouble("cash");
credit=rs.getDouble("credit");
cashbalance=rs.getDouble("cashbalance");
creditbalance=rs.getDouble("creditbalance");
note=rs.getString("note");
accountname=rs.getString("accountname");
place=rs.getString("place");
agentid=rs.getLong("agentid");
agentname=rs.getString("agentname");
returnleft=rs.getDouble("returnleft");
aim=rs.getLong("aim");
sign=rs.getString("sign");
cycle=rs.getLong("cycle");
turnma=rs.getDouble("turnma");
tmsying=rs.getDouble("tmsying");
fchsying=rs.getDouble("fchsying");
cmshu=rs.getDouble("cmshu"); return true;
}
return false;
}finally{
close();
}
} public void create()throws SQLException{
getConn();
try{
PreparedStatement ps = conn.prepareStatement("insert into xline values(NULL,NOW(),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
ps.setLong(1,userid);
ps.setString(2,username);
ps.setString(3,type);
ps.setDouble(4,cash);
ps.setDouble(5,credit);
ps.setDouble(6,cashbalance);
ps.setDouble(7,creditbalance);
ps.setString(8,note);
ps.setString(9,accountname);
ps.setString(10,place);
ps.setLong(11,agentid);
ps.setString(12,agentname);
ps.setDouble(13,returnleft);
ps.setLong(14,aim);
ps.setString(15,sign);
ps.setLong(16,cycle);
ps.setDouble(17,turnma);
ps.setDouble(18,tmsying);
ps.setDouble(19,fchsying);
ps.setDouble(20,cmshu);
ps.execute();
}finally{
close();
}
}
public void create1()throws SQLException{
getConn();
try{
PreparedStatement ps = conn.prepareStatement("insert into xline values(?,?,?,?,?,?,?,?,NULL,NOW(),?,?,?,?,?,?,?,?,?,?,?,?)");
ps.setDouble(8,returnleft);
ps.setLong(7,aim);
ps.setString(6,sign);
ps.setLong(5,cycle);
ps.setDouble(4,turnma);
ps.setDouble(3,tmsying);
ps.setDouble(2,fchsying);
ps.setDouble(1,cmshu);
ps.setLong(9,userid);
ps.setString(10,username);
ps.setString(11,type);
ps.setDouble(12,cash);
ps.setDouble(13,credit);
ps.setDouble(14,cashbalance);
ps.setDouble(15,creditbalance);
ps.setString(16,note);
ps.setString(17,accountname);
ps.setString(18,place);
ps.setLong(19,agentid);
ps.setString(20,agentname);
ps.execute();
}finally{
close();
}
}
public void delete(long xlineid)throws SQLException{
getConn();
try{
PreparedStatement ps = conn.prepareStatement("delete from xline where id=?");
ps.setLong(1,xlineid);
ps.execute();
}finally{
close();
}
}
public void update()throws java.sql.SQLException{
getConn();
try{
PreparedStatement ps = conn.prepareStatement("update xline set type=? where id=?");
ps.setString(1, type);
ps.execute();
}finally{
close();
}
} public ResultSet total(String where)throws SQLException{
getConn();
PreparedStatement ps = conn.prepareStatement(
"select accountname,sum(cash),sum(credit) from xline " + where +
" group by accountname");
ResultSet rs=ps.executeQuery();
return rs;
}
public ResultSet totaluser(String where) throws SQLException{
getConn();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select username,type,sum(cash),sum(credit) from xline " + where +
" group by username");
return rs;
}
getConn();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select agentname,type,sum(cash),sum(credit) from xline " + where +
" group by agentname");
return rs;
}
public ResultSet sel(String where) throws SQLException{
getConn();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from xline " + where);
return rs;
}
public void dealuser(String username,String accountname,String newtype,String newnote,double in,double out)throws SQLException{
dbUsers user=new dbUsers();
dbAgents agent=new dbAgents();
dbAccounts account=new dbAccounts();
if (user.lookup(username)&&agent.lookup(user.getAgentid())&&account.lookup(accountname)) {
double x=user.getCash();
this.userid=user.getUserid();
this.username=user.getUsername();
this.type=newtype;
this.note=newnote;
this.agentid=agent.getAgentid();
this.agentname=agent.getAgentname();
this.accountname=account.getAccountname();
this.place=account.getPlace();
if(in>0){
this.setCash(in);
this.setCredit(0);
user.setCash(x + in);
}
agent.update();
} if(out>0){
this.setCash(-out);
this.setCredit(0);
user.setCash(user.getCash()-out);
}else{
}
user.update();
this.cashbalance=user.getCash();
this.creditbalance=user.getCredit();
create1();
} public void dealother(String username,String accountname,String newtype,String newnote,double in)throws SQLException{
dbUsers user=new dbUsers();
dbAgents agent=new dbAgents();
dbAccounts account=new dbAccounts();
if (user.lookup(username)&&agent.lookup(user.getAgentid())&&account.lookup(accountname)) {
this.userid=user.getUserid();
this.username=user.getUsername();
this.type=newtype;
this.note=newnote;
this.agentid=agent.getAgentid();
this.agentname=agent.getAgentname();
this.accountname=account.getAccountname();
this.place=account.getPlace(); if(in>0){
this.setCash(in);
this.setCredit(0);
}
else{
}
this.cashbalance=user.getCash();
this.creditbalance=user.getCredit();
create();
}
}
public void dealagent(long agentid,String accountname,String newtype,String newnote,double in,double out)throws SQLException{
dbUsers user=new dbUsers();
dbAgents agent=new dbAgents();
dbAccounts account=new dbAccounts();
if (agent.lookup(agentid)&&account.lookup(accountname)) {
double x=agent.getCashbalance();
this.type=newtype;
this.note=newnote;
this.agentid=agent.getAgentid();
this.agentname=agent.getAgentname();
this.accountname=account.getAccountname();
this.place=account.getPlace(); if(in>0){
this.setCash(in);
this.setCredit(0);
agent.setCashbalance(x + in);
}
agent.update();
} if(out>0){
this.setCash(-out);
this.setCredit(0);
agent.setCashbalance(agent.getCashbalance()-out);
}else{
}
agent.update();
this.cashbalance=agent.getCashbalance();
this.creditbalance=agent.getCreditleft();
create1();
} public void dealback(String username,String accountname,String newtype,String newnote,long newcycle,long newaim,double newcredit, double in,double out)throws SQLException{
dbUsers user=new dbUsers();
dbAgents agent=new dbAgents();
dbAccounts account=new dbAccounts();
if (user.lookup(username)&&agent.lookup(user.getAgentid())&&account.lookup(accountname)) {
this.userid=user.getUserid();
this.username=user.getUsername();
this.type=newtype;
this.note=newnote;
this.credit=newcredit;
this.agentid=agent.getAgentid();
this.agentname=agent.getAgentname();
this.accountname=account.getAccountname();
this.place=account.getPlace();
if(in!=0){
if(in<-newcredit){
user.setCredit(user.getCredit() + in);
this.setCredit(in);
this.setReturnleft(newcredit-in);
this.setAim(newaim);
this.setSign("N");
}
else{
user.setCredit(user.getCredit() + in);
this.setCredit(in);
this.setReturnleft(0);
this.setAim(newaim);
this.setSign("Y");
}
user.update();
}else if(out!=0){
if(out<user.getCredit()){ double x=user.getCash()+user.getCredit();
user.setCredit(user.getCredit()-out);
this.setCredit(-out);
this.setCycle(newcycle);
}else if(user.getCredit()<out){
user.setCredit(user.getCredit()-out);
this.setCredit(-out);
this.setCycle(newcycle);
}
else{
}
}else{
}
user.update();
}
this.cashbalance=user.getCash();
this.creditbalance=user.getCredit();
create();
}
public void dealget(String username,String accountname,String newtype,String newnote,long newcycle,double out)throws SQLException{
dbUsers user=new dbUsers();
dbAgents agent=new dbAgents();
dbAccounts account=new dbAccounts();
if (user.lookup(username)&&agent.lookup(user.getAgentid())&&account.lookup(accountname)) {
this.userid=user.getUserid();
this.username=user.getUsername();
this.type=newtype;
this.note=newnote;
this.cycle=newcycle;
this.agentid=agent.getAgentid();
this.agentname=agent.getAgentname();
this.accountname=account.getAccountname();
this.place=account.getPlace();
double x=user.getCredit()+user.getCash();
if(user.getCredit()>out&&out>0){
this.setCash(0);
this.setCredit(-out);
user.setCredit(user.getCredit()-out);
agent.setCreditleft(agent.getCreditleft()-out);
user.update();
agent.update();
} else if(user.getCredit()<out&&out<x){
this.setCash(0);
this.setCredit(-out);
user.setCredit(user.getCredit()-x);
agent.setCreditleft(agent.getCreditleft()-x);
user.update();
agent.update();
}
else{
}
this.cashbalance=user.getCash();
this.creditbalance=user.getCredit();
create();
}
}
}
<%while(rs.next()){%>
<tr bgcolor="#FFFFFF" class="style10">
<td align="center"><%=rs.getString("t")%></td>
<td align="center"><%=rs.getString("accountname")%></td>
<td align="center"><%=rs.getString("username")%></td>
<td align="center"><%=rs.getString("place")%></td>
<td align="center" ><%=rs.getString("cash")%></td>
<td align="center">non</td>
<td align="center"><%=rs.getString("cycle")%></td>
<td align="right"><input name="button22" type="button" onClick="WinOpen('agent_iou_re.jsp')" value="Update" ></td>
</tr><%}%>
最后结果集要关掉!
哦,记得所有建立的stamt、con、rs的地方使用完了都要关闭!
finally{
close();
}
所以你的结果集就在调用这些方法后就关闭了,而你的JSP页面里的rs就关闭了,rs是引用传递的,所以在你的rs.next()之后才应该关闭连接。你删除了close();再在你的JSP页面最后再加上close()就应该可以了。
顺便说一下,你这样写类是不规范的,你里面的属性和他的getter和setter方法用一个类来封装,实现操作方法用另一个类d~~~~