80,351
社区成员
发帖
与我相关
我的任务
分享
Network error IOException: Connection timed out
/**
*
* @param server 数据库地址
* @param dbName 数据库名称
* @param userName 用户名
* @param userPwd 密码
*/
public MyJTDS(String server, String dbName, String userName, String userPwd) {
this.server = server;
this.dbName = dbName;
this.userName = userName;
this.userPwd = userPwd;
this.connStr = "jdbc:jtds:sqlserver://" + this.server + ":1433/" + this.dbName;
new Thread(new Runnable() {
@Override
public void run() {
Log.d("new Thread:","Start new Thread!");
try { // 加载驱动程序
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
Log.d("Connecting","Loading....");
con = DriverManager.getConnection(connStr, userName, userPwd);
//这一句(第21行)是发生异常的位置,异常信息在上面有
testConnection(con);
Log.d("Success:","Connect Database successfully!");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace();
} catch (NetworkOnMainThreadException e) {
e.printStackTrace();
e.printStackTrace();
}catch (IllegalAccessException ie){
ie.printStackTrace();
}catch (InstantiationException ie){
}
}
}).start();
}