我尝试从我的 Android 应用程序连接到我在 Windows 7 上运行的 postgresql 服务器。两者都在我的计算机上运行,具有特殊的 IP。我试试
String url = "jdbc:postgresql://xx.xx.xx.xx:5432/postgis20";
connect = DriverManager.getConnection(url,"postgres","xxxx");
该应用程序正在我电脑上的模拟器中运行。 Connect contains after the procedure null and Exceiption I get is The connection attempt failed. 那么我在连接上做错了什么? 如果我尝试通过 SQL Shell 连接,一切正常,并且我使用相同的参数。 SSL 设置为否。
我也尝试使用 ip localhost 或 127.0.0.1 来代替,但结果相同。
我更改了权限设置以允许访问互联网。 但是现在我收到以下错误:org.postgresql.util.PSQLException:发生异常导致驱动程序失败。请报告此异常。
最佳答案
要在 Android 上使用 jdbc,必须使用 StrictMode。这可以通过使用以下代码行来完成:
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
关于java - Postgresql 与 Java 中的数据库连接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16666619/