Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 235
user617389 Avatar asked Feb 15 '11 07:02

user617389


People also ask

Can I use PostgreSQL on Android?

Install and configure PostgreSQL on Termux Once you have successfully installed this set of scripts, you can use your Android tablet or smartphone as a PostgreSQL clone database server.

Does JDBC work with PostgreSQL?

JDBC APIs make use of JDBC drivers to get access to databases like PostgreSQL. JDBC APIs other than accessing the tabular data, also enable you to perform operations on the databases. You can perform save, update, delete, and fetch operations on the data stored in any database using JDBC.


2 Answers

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.

like image 164
Greg Smith Avatar answered Oct 21 '22 18:10

Greg Smith


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.

like image 24
Lukas Eder Avatar answered Oct 21 '22 17:10

Lukas Eder