JDBC adapter

172 views
Skip to first unread message

Michael Welter

unread,
Nov 9, 2010, 5:06:04 PM11/9/10
to pgan...@googlegroups.com
Hello,

Newbie to Android.

Does a JDBC adapter exist so that an Android phone can send Selects and Updates to a pg database?

Thanks,

Dave Cramer

unread,
Nov 10, 2010, 7:02:25 AM11/10/10
to pgan...@googlegroups.com

Mark Wong

unread,
Nov 10, 2010, 10:05:52 AM11/10/10
to pgan...@googlegroups.com

Build 801 seems to be working for me. I assumed it was because the
changes Dave made are in there.

Regards,
Mark

Dave Cramer

unread,
Nov 10, 2010, 10:17:36 AM11/10/10
to pgan...@googlegroups.com
Interesting I did not push the changes back. The only change I made
was to remove an object that was not available in the android library.

DAve

Mark Wong

unread,
Nov 10, 2010, 10:27:27 AM11/10/10
to pgan...@googlegroups.com
If I were to make another wild guess, Magnus patched my program up to
use the 2.2 api's, where I was previously using 1.5 or 1.6. Perhaps
the later android jars now has that missing object?

Mark

Dave Cramer

unread,
Nov 10, 2010, 10:38:29 AM11/10/10
to pgan...@googlegroups.com
Here is the diff

Index: org/postgresql/jdbc2/AbstractJdbc2Connection.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v
retrieving revision 1.54
diff -r1.54 AbstractJdbc2Connection.java
172c172,173
< initObjectTypes(info);
---
> // remove for android
> //initObjectTypes(info);

I can't remember exactly which object android does not like.

Dave

Michael Welter

unread,
Nov 10, 2010, 1:57:19 PM11/10/10
to pgan...@googlegroups.com
Still no joy.

From the code:

    

    <string name="dbDriver">org.postgresql.Driver</string>
    <string name="dbURL">jdbc:postgresql://localhost:5432/canvass</string>
    <string name="dbUser">postgres</string>
    <string name="dbPass">xxx</string>

Class.forName( getString( R.string.dbDriver ) ); // load the driver
Connection conn = DriverManager.getConnection( getString( R.string.dbURL ),getString( R.string.dbUser),getString( R.string.dbPass ) );

I consistently get:
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

The URL 'jdbc:postgresql:canvass' results in the same PSQLException.

I've tried the driver posted by Dave Cramer as well as the 801 driver from the PostgreSQL site. PostgreSQL version is 8.4, started with -i.  OS X, firewall off.

From postgresql.conf:
listen_addresses = '*'

From pg_hba.conf:
host    all         all         127.0.0.1/32          trust
host    all         all         0.0.0.0/0          trust
host    all         all         192.168.0.0/16

The only quirky thing is the following:
psql -h localhost -d canvass
psql: FATAL:  cache lookup failed for database 16384

Can anyone offer any suggestions?

Thanks,
Mike


I can access the database from psql.

Dave Cramer

unread,
Nov 10, 2010, 2:56:32 PM11/10/10
to pgan...@googlegroups.com
What ip address is the machine hosting the database ? localhost seems
like a long shot presuming android is not running on the machine but
on your emulator or device ?

Dave

Michael Welter

unread,
Nov 10, 2010, 2:59:02 PM11/10/10
to pgan...@googlegroups.com
The IP is 192.168.1.33.

Michael Welter

unread,
Nov 10, 2010, 3:03:21 PM11/10/10
to pgan...@googlegroups.com
Thanks, Dave. Putting 192.168.1.33 in the URL allowed it to connect.

Mike

On Nov 10, 2010, at 12:56 PM, Dave Cramer wrote:

Valentin Dodov

unread,
Dec 9, 2010, 4:46:16 AM12/9/10
to PgAndroid
Hello,

i'm absolutely new in Andorid and have a little question.

Where should I put this jar library to make my program work?

Thanks

On Nov 10, 2:02 pm, Dave Cramer <davecra...@gmail.com> wrote:
> Yes, I believe I posted it
>
> http://groups.google.com/group/pgandroid/browse_thread/thread/d8b400f...

Mark Wong

unread,
Dec 9, 2010, 1:35:42 PM12/9/10
to pgan...@googlegroups.com
On Thu, Dec 9, 2010 at 1:46 AM, Valentin Dodov <vald...@gmail.com> wrote:
> Hello,
>
> i'm absolutely new in Andorid and have a little question.
>
> Where should I put this jar library to make my program work?

The location of the jar doesn't really matter. If you're using
eclipse, I think these instructions are accurate:

http://stackoverflow.com/questions/179024/adding-a-jar-to-an-eclipse-java-library

If not, I think you only need to edit the .classpath file appropriately:

<classpathentry kind="lib" path="/tmp/postgresql.jar"/>

Regards,
Mark

Mark Wong

unread,
Jan 20, 2011, 11:14:39 AM1/20/11
to pgan...@googlegroups.com
I played with this a little more. The released jars work on android
2.1 and 2.1, but not 1.6. I figured it wasn't worth trying it again
1.5. :) So if for whatever reason 1.6 is required, you'll have to use
the special one Dave posted to the list.

Regards,
Mark

Reply all
Reply to author
Forward
0 new messages