Invalid state, the Connection object is closed.

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();
   }

你可能感兴趣的:(多线程,sql,mysql,SQL Server,sun)