I have this problem that my Android app cannot connect directly with a Postgres databse and cannot use JDBC connections. I've browsed the web a bit and some people say, that the best way to deal with this is to run a web service. I'm absolutely lost on how to tackle this problem. Should I build an extension of some sort or... ? Thanks in advance for the help.
Asked
Active
Viewed 7,308 times
0
-
Android can connect `PostgreSQL` using `JDBC`, please look at: http://stackoverflow.com/questions/10903481/java-lang-classnotfoundexception-org-postgresql-driver-android/21812893#21812893 – Houari Feb 25 '14 at 21:04
-
2A huge reason you should NEVER have a direct database connection inside your Android application is that your database credentials will not be secure. If you want to make database requests, you should use the approach of a web-server that securely talks to the database and returns the desired result to your application. – Cruceo Feb 25 '14 at 21:11
2 Answers
2
It's possible to use JDBC with pgJDBC on newer Android versions, but not a good idea.
See JDBC vs Web Service for Android and Driver JDBC PostgreSQL with Android for why.
Basically, if you're on a device with potentially flakey connectivity, you don't want a persistent connection if you can use stateless HTTP requests instead.

Community
- 1
- 1

Craig Ringer
- 307,061
- 76
- 688
- 778
0
You can never have a direct access to a database which is on a server. For this you need to run some server side code and use JSON to interact your app with server
This tutorial might be of help to you:Connect android with PHP Mysql
And instead of connecting to MYSQL you can connect to PostgreSQL with the help of these docs:

Milen A. Radev
- 60,241
- 22
- 105
- 110

ofnowhere
- 1,114
- 2
- 16
- 40