无法连接到android数据库

时间:2018-04-05 16:26:21

标签: java android mysql database jtds

我正在尝试通过我正在创建的Android应用程序连接到Azure数据库,但是我不断收到此特定错误: Network error IOException: Could not create socket

我可以成功连接到我的登录活动数据库,但是如果我在不同的活动上重复使用相同的代码,它将根本无法连接。

我试图重新格式化连接字符串,但问题仍然存在。这是我当前连接的代码,在登录活动中是相同的:

String username = "username";
String password = "password";
String host = "jdbc:jtds:sqlserver://databaseUrl:1433/database"

try {
        Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
        System.out.println("Connecting to database for duty...");
        Connection conn = DriverManager.getConnection(host, username, password);
        System.out.println("connected");
} catch (SQLException err) {
        System.err.println(err.getMessage());
} catch (Exception e) {
        System.err.println(e.getMessage());
}

非常感谢任何帮助

0 个答案:

没有答案