That line makes me nervous.
快疯掉了,从昨晚到现在一直没有解决的问题;前天写了一个导入程序;
JDK1.5+jTDS1.2.2+SQL SERVER 2000(SP3)+MySQL5;
从MySQL中导入抓取回来的数据,到SQL SERVER里,程序跑了一会就提示上面那错误:
java.sql.SQLException: Invalid state, the Connection object is closed.
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.checkOpen(ConnectionJDBC.java:249)
折腾了一整天,还是没把问题解决,网上找了N多资料,看来这个问题相当少见,只在SUN的官方上找到一篇http://forum.java.sun.com/thread.jspa?threadID=678409&start=0&tstart=0
SQL SERVER也调试了,Connection打印出来也是是没有closed的,但都总是出现这个问题,真的快疯了;
请有经验的给点提示,小弟将发自内心的感谢!
public void insertMsData(......) {
Connection conn=null;
Statement stmt1=null;
Statement stmt2=null;
Statement stmt3=null;
String lname="重录";
String COM_ID=(getComid()+1)+"";
String Lnk_ID=(getLnkid()+1)+"";
String DeptName="人事部";
int j=0;
int t=0;
int k=0;
String sql="INSERT INTO CRM_Company ......";
String sql1="INSERT INTO CRM_Linkman (Lnk_ID,COM_ID,Lnk_Name,DeptName,Sex,PosType,SensType,Phone_Z,Phone_N,IsAdmin,DelFlag,RegisterDate) VALUES ("+Lnk_ID+","+Integer.parseInt(COM_ID)+",'"+lname+"','"+DeptName+"',"+1+","+3+","+1+","+0000+","+00000000+","+1+","+0+",convert(smalldatetime,"+RegisterDate+"))";
String sql2="INSERT INTO ShieldTable (S_ID,S_Company) VALUES ('"+COM_ID+"','"+COM_Name+"')";
try {
if (conn==null || conn.isClosed()) {
conn=dbc.getMSConnection();
}
System.out.println("@@@@@@@@conn:"+conn);
stmt1=conn.createStatement();
j=stmt1.executeUpdate(sql);
stmt2=conn.createStatement();
t=stmt2.executeUpdate(sql1);
stmt3=conn.createStatement();
k=stmt3.executeUpdate(sql2);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(0);
}finally{
try {
if(stmt1!=null){
stmt1.close();
}
if(stmt2!=null){
stmt2.close();
}
if(stmt3!=null){
stmt3.close();
}
if(conn!=null){
conn.close();
conn=null;
}
} catch (SQLException e) {
e.printStackTrace();
}
评论
你这应该是个多线程的环境,多线程要好好看看connection,statement等有没有互相引用的,可能是一个线程打开一个资源,用完后要关闭,可在关闭前被另一个线程使用,这样前一个线程关闭了资源,而另外哪个线程在调用时就会出错。
Posts:41
Registered: 26/03/04 Re: Invalid state, the Connection object is closed.
2006-3-1 ??3:55 (reply 12 of 15)
My workaround was changing the connection pool and upgrading jTDS. Now I'm using proxool and the new version of jTDS and I do not have these problems so often, but I could never figure out what was the real problem.
MarcoTulioBorges
Posts:41
Registered: 26/03/04 Re: Invalid state, the Connection object is closed.
2008-3-13 ??7:38 (reply 14 of 15)
My solution was to drop the old implementation, the "made by hand" one that made Saish nervous :-) and start using Proxool and an updated version of Jtds. I don't remember what version I used at that time, but nowadays I use Proxool 0.9.0RC3 and Jtds 1.2.2 and they work just fine. It's been a while since my last reply on this thread, so I don't really remember all the details, but I hope this info can help you.
THANKS
MarcoTulioBorges
但是我已经是1.2.2的版本了,看来updated version这招不行了,晕死了;







评论排行榜