【问题标题】:Postgresql Connection with Database in Java failPostgresql 与 Java 中的数据库的连接失败
【发布时间】:2013-05-21 09:30:01
【问题描述】:

我尝试从我的 Android 应用程序连接到我在 Windows 7 上运行的 postgresql 服务器。两者都在我的计算机上以特殊 IP 运行。我试试

String url = "jdbc:postgresql://xx.xx.xx.xx:5432/postgis20";
connect = DriverManager.getConnection(url,"postgres","xxxx");

该应用程序正在我的电脑上的模拟器中运行。 Connect 包含在程序 null 之后,我得到的异常是 连接尝试失败。 那么我对连接做错了什么? 如果我尝试通过 SQL Shell 进行连接,一切正常,我使用相同的参数。 SSL 设置为 no。

我也尝试使用 ip localhost 或 127.0.0.1 代替,但结果相同。

我更改了权限设置以允许访问互联网。 但现在我收到以下错误:org.postgresql.util.PSQLException:发生异常情况导致驱动程序失败。请报告此异常。

【问题讨论】:

    标签: java android jdbc postgis postgresql-9.2


    【解决方案1】:

    要在 Android 上使用 jdbc,必须使用 StrictMode。这可以通过使用以下代码行来完成:

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    

    【讨论】:

      猜你喜欢
      • 2021-03-06
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      相关资源
      最近更新 更多