| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 476 人关注过本帖
标题:JDBC连接池报异常
只看楼主 加入收藏
dongyongbo
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2007-3-20
收藏
 问题点数:0 回复次数:1 
JDBC连接池报异常

package fixedassets;

import java.sql.*;
import javax.swing.tree.DefaultMutableTreeNode;


public class JDBC {
Statement st=null;
ResultSet rs2=null;
ResultSet rs=null;
public JDBC() {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=AssetsManage","sa","sa");
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public ResultSet yan(String s,String s1) {//验证用户名和密码
ResultSet rsa=null;
try {
rsa = st.executeQuery("select *from operater where ID='"+s+"'and PassWord='"+s1+"'");
} catch (SQLException ex) {
ex.printStackTrace();
}
return rsa;
}
public int chaxun(String s,int i) {//查询数据
try {
if(i==0) {//以资产编号查询
clear();
rs = st.executeQuery("select *from asset where aId="+s);
}else if(i==1) {//以资产名称查询
clear();
rs = st.executeQuery("select *from asset where aName='"+s+"'");
}
if(rs.next()) {
zhi();
}

} catch (SQLException ex) {
ex.printStackTrace();
}
return 0;
}

/*错误就在这个方法里,上面的chaxun()方法调用本方法来把查询出来的信息显示在文本框内,第一次调用时信息都可以提出来没问题,但是我想做一个导航条,可以通过按钮点击来查看数据,所以我在另外一个类里做了一个按钮事件,当点击时就zhi()这个方法,就在这里就报异常了,异常如下:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Object has been closed.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.validateClosedState(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getString(Unknown Source)
at fixedassets.JDBC.zhi(JDBC.java:68)
at fixedassets.Frame3.jButton4_actionPerformed(Frame3.java:405)
at fixedassets.Frame3_jButton4_actionAdapter.actionPerformed(Frame3.java:431)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

我在网上查了一下,好像是说连接池被已关闭,但是我所有的连接一个也没关啊,不知道是怎么回事,急~!请各位高手帮忙看一下*/

public void zhi() {
try {
String s3 = rs.getString(1);
String s10 = rs.getString(2);
String s11 = rs.getString(3);
String s5 = rs.getString(4);
String s6 = rs.getString(8);
String s7 = rs.getString(9);
String s8 = rs.getString(7);
String s12 = rs.getString(5);
String s13 = rs.getString(6);
String s14 = rs.getString(10);
Frame3.jTextField3.setText(s3);
Frame3.jTextField5.setText(s5);
Frame3.jTextField6.setText(s6);
Frame3.jTextField10.setText(s10);
Frame3.jTextField11.setText(s11);
Frame3.jTextField12.setText(s12);
if (s13.equals("0")) {
Frame3.jTextField13.setText("正常");
} else if (s13.equals("1")) {
Frame3.jTextField13.setText("维修");
} else if (s13.equals("2")) {
Frame3.jTextField13.setText("报废");
}
Frame3.jTextField14.setText(s14);

if (Frame3.i == 1) { //通过游标判断是否可以上下翻页
if (rs.next()) {
Frame3.jButton4.setEnabled(true);
} else {
Frame3.jButton4.setEnabled(false);
}
} else {
if (rs.previous()) {
Frame3.jButton3.setEnabled(true);
} else {
Frame3.jButton3.setEnabled(false);
}
}

ResultSet rls = st.executeQuery(
"select eName from employee where eId=" +
s7);
rls.next();
Frame3.jTextField7.setText(rls.getString(1));
ResultSet rs1 = st.executeQuery(
"select type from cateGory where cateId='" + s11 + "'");
rs1.next();
String s4 = rs1.getString(1);
if (s4.equals("0")) {
Frame3.jTextField4.setText("");
} else {
Frame3.jTextField4.setText(s4);
}

if (!(s8 == null)) {
ResultSet rls1 = st.executeQuery(
"select eName from employee where eId=" + s8);
rls1.next();
Frame3.jTextField8.setText(rls1.getString(1));
rs2 = st.executeQuery("select *from lend where aId=" +
s3);
rs2.last();
String s9 = rs2.getString(4);
String s15 = rs2.getString(3);
String s16 = rs2.getString(5);
Frame3.jTextField9.setText(s9);
Frame3.jTextField15.setText(s15);
if (s16.equals("0")) {
Frame3.jTextField16.setText("否");
} else if (s16.equals("1")) {
Frame3.jTextField16.setText("是");
}
}

} catch (Exception a) {
System.out.println("asdfwdfasdf");
a.printStackTrace();
}
}


public void clear() {//清空
Frame3.jTextField3.setText("");
Frame3.jTextField4.setText("");
Frame3.jTextField5.setText("");
Frame3.jTextField6.setText("");
Frame3.jTextField7.setText("");
Frame3.jTextField8.setText("");
Frame3.jTextField9.setText("");
Frame3.jTextField10.setText("");
Frame3.jTextField11.setText("");
Frame3.jTextField12.setText("");
Frame3.jTextField13.setText("");
Frame3.jTextField14.setText("");
Frame3.jTextField15.setText("");
Frame3.jTextField16.setText("");
}

}

搜索更多相关主题的帖子: public package localhost microsoft null 
2007-08-06 16:22
dongyongbo
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2007-3-20
收藏
得分:0 
回复:(dongyongbo)JDBC连接池报异常
报异常的方法是zhi().
2007-08-06 16:23
快速回复:JDBC连接池报异常
数据加载中...
 
   



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

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