6

This is my first post on stackoverflow so hopefully I don't sound too incompetent. I'm having an issue connecting my Android App to a PostgresDB that I created. I used the code from this tutorial http://appliedcoffeetechnology.tumblr.com/post/10657124340. Although I modified the String url ... line to the following: String url = "jdbc:postgresql://192.168.1.101:5556/postgres?user=postgres&password=yeahright"; I followed the other instructions on downloading the JDBC and adding it to the package, I also added the internet permissions line.

I've configured the postgreSQL DB on my Windows 7 machine to allow connections, and even set the incoming connections to "trust" so that the password won't get in the way. I also opened up the 5556 port on the Windows firewall. I can connect to it from my Ubuntu laptop, using the following command: psql 192.168.1.101 -U postgres -p 5556 -d postgres However, when running the Android App (on a real device) I get "java.sql.SQLException: No suitable driver" thrown by the conn = DriverManager.getConnection(url) call.

Thank you greatly in advance for your help, and let me know if I can provide any other useful information.

Craig Ringer below mentioned a web service app. Originally I was hesitant as I didn't want to add an even steeper incline to my learning curve, but I decided to go with Django, and it has been amazingly simple.

Lokist
  • 242
  • 4
  • 10

2 Answers2

3

AFAIK Android doesn't support JDBC natively. (Update: newer versions do). Honestly, you're WAY better off running a web service and having your Android app communicate with the DB via web service requests.

Search SO for "android postgresql".

Some related discussions:

Community
  • 1
  • 1
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • I'm kinda crunched for time, is there any way that you know of where I can get something simple up and running? It's been a long time since I set up a webservice, and the DB host is a Windows machine, which usually means there are very few resources on configuring it. For right now there will be two Android devices using the DB and queries/modifications will be fairly far apart. If the webservice is the only way to go, I understand. – Lokist Oct 03 '12 at 16:00
  • Looking at one of the posts you listed above (How to create webservice in java using apache tomcat using PostgreSQL) you mentioned JBoss AS 7, Jersey, and RESTEasy. I assume that if I go with JBoss AS 7 then I don't need to look into Jersey or RESTEasy. Is that correct? – Lokist Oct 03 '12 at 17:11
  • @Lokist Lots of people hack stuff together with PHP etc. Pick an already-familiar language and build something with it using a REST service library for that language. I find JAX-RS on Java application servers easy; you might prefer something else. A search for "REST" and your language of choice might be informative. – Craig Ringer Oct 03 '12 at 23:08
1

The error message you get indicates that you did not copy the postgres jdbc driver jar into your application.

Having said that, direct SQL connections to a remote database perhaps even going over a 3g network may not give the performance that you desire.

If you just need a database in your application to store some stuff you should look at the embedded SQLite database.

Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119
  • The .jar file ends up inside the "Referenced Libraries" section. Is there something else I should look at to determine whether or not the jar is making it into the package? I'm actually storing the DB on a remote windows server so that multiple Android devices can access it at once. That being said, performance really shouldn't be an issue, maybe a max of 10 queries in a second. Thanks! – Lokist Oct 03 '12 at 15:54
  • FYI, this will be over WiFi only. – Lokist Oct 03 '12 at 21:46