如何在 Android 中通过 JDBC 连接到 PostgreSQL 服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5001066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-20 00:33:22  来源:igfitidea点击:

How to connect to a PostgreSQL server via JDBC in Android?

androiddatabasepostgresqljdbc

提问by user617389

I have to connect to a PostgreSQL server in LAN without web service. At the moment I think JDBC is the only way I can consider of.

我必须在没有 Web 服务的情况下连接到 LAN 中的 PostgreSQL 服务器。目前我认为 JDBC 是我能考虑的唯一方法。

How can I fulfill this? Is there any ready-to-use 3rd party library I can import to my Android project?

我怎样才能做到这一点?是否有任何现成的 3rd 方库可以导入到我的 Android 项目中?

Any reply would be appreciated.

任何答复将不胜感激。

采纳答案by Lukas Eder

If a direct connection between mobile devices and the database server is really what you want (no security concerns) then you wouldn't need any additional library? Just deploy the JDBC driver on android, I guess...?

如果移动设备和数据库服务器之间的直接连接确实是您想要的(没有安全问题),那么您将不需要任何额外的库?只需在 android 上部署 JDBC 驱动程序,我猜...?

An other option would be to create a mini web server in front of the PosgreSQL server, containing the JDBC driver. Then you could define a simple protocol of sending/receiving SQL/resultsets via HTTP. The advantage of this is, your application footprint on the mobile device is smaller.

另一种选择是在 PosgreSQL 服务器前面创建一个包含 JDBC 驱动程序的小型 Web 服务器。然后您可以定义一个通过 HTTP 发送/接收 SQL/结果集的简单协议。这样做的好处是,您在移动设备上的应用程序占用空间更小。

回答by Greg Smith

You can find people talking about deploying the JDBC driver to talk to PostgreSQL on the pgandroidmailing list. Some examples there and if you run into problems that's the right place to ask for help. I believe the regular .jar files work fine with recent Android versions, but you may have to patch things to add compatibility with older Android versions.

您可以在pgandroid邮件列表上找到谈论部署 JDBC 驱动程序以与 PostgreSQL对话的人。那里有一些例子,如果你遇到问题,这是寻求帮助的正确地方。我相信常规 .jar 文件适用于最近的 Android 版本,但您可能需要修补内容以增加与旧 Android 版本的兼容性。

The other option if you don't want to use Java/JDBC is to use the psqldroidlibrary.

如果您不想使用 Java/JDBC,另一个选择是使用psqldroid库。