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();
}
分享到:
相关推荐
Invalid State Update(解决方案).md
Invalid State Key(解决方案).md
Invalid State Mutation(解决方案).md
java.lang.IllegalStateException: Invalid name=“com.alibaba.dubbo.config.ProtocolConfig#0” contains illegal character, only digit, letter, ‘-’, ‘_’ or ‘.’ is legal 原因: 如果没有指定id属性,...
Invalid Pipeline State(处理方案).md
Invalid Model State(解决方案).md
Invalid Render State(解决方案).md
Invalid Initial State(解决方案).md
Invalid Context State(解决方案).md
InvalidSignature-The signature is invalid(解决方案).md
Invalid Connection Pool(解决方案).md
Invalid Connection Point(解决方案).md
Invalid Object Type(解决方案).md
Invalid Object Scaling(解决方案).md
Invalid Object Transformation(解决方案).md
Invalid Object Rotation(解决方案).md
Invalid Object ID(解决方案).md
invalid return type(解决方案).md
Invalid Login Credentials(解决方案).md
Invalid Subnet Mask(解决方案).md