Home » Android » database – How to connect to a PostgreSQL server via JDBC in Android?

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

Posted by: admin June 15, 2020 Leave a comment

Questions:

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.

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

Any reply would be appreciated.

How to&Answers:

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…?

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.

Answer:

You can find people talking about deploying the JDBC driver to talk to PostgreSQL on the pgandroid mailing 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.

The other option if you don’t want to use Java/JDBC is to use the psqldroid library.