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.

2
  • Android version? Target device(s)? Commented Oct 3, 2012 at 4:37
  • Running Ice-Cream-Sandwich on a Galaxy S Tab2 10.1 Commented Oct 3, 2012 at 15:01

2 Answers 2

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:

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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 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.
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.

2 Comments

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!
FYI, this will be over WiFi only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.