Jdbc driver problem

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Jdbc driver problem

Postby spenko » Mon Aug 24, 2009 10:24 am

Hi all.
I am new to this forum and I wanted to congratulate the managers for the excellent community that they created.
Like object i have some problem with jdbc driver.

I wanna connect to a database server (postgresql) without write some
php script server side to comunicate with client (android mobile
phone), so can i use this driver?

http://jdbc.postgresql.org/

I try it in a normal java program and it works very well but when I
use this library in android program I have this exception (logcat
paste):

08-24 08:15:11.072: INFO/ActivityManager(568): Starting activity:
Intent { flags=0x10000000 comp={com.prova.pgsql/
com.prova.pgsql.PGSQL} }
08-24 08:15:11.132: INFO/ActivityManager(568): Start proc
com.prova.pgsql for activity com.prova.pgsql/.PGSQL: pid=767 uid=10023
gids={}
08-24 08:15:11.152: DEBUG/AndroidRuntime(760): Shutting down VM
08-24 08:15:11.152: DEBUG/dalvikvm(760): DestroyJavaVM waiting for non-
daemon threads to exit
08-24 08:15:11.172: DEBUG/dalvikvm(760): DestroyJavaVM shutting VM
down
08-24 08:15:11.172: DEBUG/dalvikvm(760): HeapWorker thread shutting
down
08-24 08:15:11.172: DEBUG/dalvikvm(760): HeapWorker thread has shut
down
08-24 08:15:11.172: DEBUG/jdwp(760): JDWP shutting down net...
08-24 08:15:11.172: DEBUG/jdwp(760): +++ peer disconnected
08-24 08:15:11.172: INFO/dalvikvm(760): Debugger has detached; object
registry had 1 entries
08-24 08:15:11.182: DEBUG/dalvikvm(760): VM cleaning up
08-24 08:15:11.232: DEBUG/dalvikvm(760): LinearAlloc 0x0 used 639228
of 4194304 (15%)
08-24 08:15:11.362: INFO/jdwp(767): received file descriptor 20 from
ADB
08-24 08:15:11.451: DEBUG/dalvikvm(541): GC freed 264 objects / 9912
bytes in 329ms
08-24 08:15:11.682: DEBUG/dalvikvm(541): GC freed 40 objects / 1696
bytes in 212ms
08-24 08:15:11.792: DEBUG/dalvikvm(541): GC freed 2 objects / 48 bytes
in 107ms
08-24 08:15:11.892: INFO/dalvikvm(767): Failed resolving Lorg/
postgresql/jdbc4/Jdbc4SQLXML; interface 131 'Ljava/sql/SQLXML;'
08-24 08:15:11.892: WARN/dalvikvm(767): Link of class 'Lorg/postgresql/
jdbc4/Jdbc4SQLXML;' failed
08-24 08:15:11.892: ERROR/dalvikvm(767): Could not find class
'org.postgresql.jdbc4.Jdbc4SQLXML', referenced from method
org.postgresql.jdbc4.AbstractJdbc4Connection.createSQLXML
08-24 08:15:11.892: WARN/dalvikvm(767): VFY: unable to resolve new-
instance 391 (Lorg/postgresql/jdbc4/Jdbc4SQLXML;) in Lorg/postgresql/
jdbc4/AbstractJdbc4Connection;
08-24 08:15:11.892: WARN/dalvikvm(767): VFY: rejecting opcode 0x22 at
0x0000
08-24 08:15:11.892: WARN/dalvikvm(767): VFY: rejected Lorg/postgresql/
jdbc4/AbstractJdbc4Connection;.createSQLXML ()Ljava/sql/SQLXML;
08-24 08:15:11.892: WARN/dalvikvm(767): Verifier rejected class Lorg/
postgresql/jdbc4/AbstractJdbc4Connection;
08-24 08:15:11.892: DEBUG/AndroidRuntime(767): Shutting down VM
08-24 08:15:11.892: WARN/dalvikvm(767): threadid=3: thread exiting
with uncaught exception (group=0x4000fe70)
08-24 08:15:11.892: ERROR/AndroidRuntime(767): Uncaught handler:
thread main exiting due to uncaught exception
08-24 08:15:11.902: ERROR/AndroidRuntime(767): java.lang.VerifyError:
org.postgresql.jdbc4.AbstractJdbc4Connection
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
org.postgresql.Driver.makeConnection(Driver.java:393)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
org.postgresql.Driver.connect(Driver.java:267)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
java.sql.DriverManager.getConnection(DriverManager.java:192)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
java.sql.DriverManager.getConnection(DriverManager.java:228)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
com.prova.pgsql.PGSQL.onCreate(PGSQL.java:32)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2231)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
android.os.Handler.dispatchMessage(Handler.java:99)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
android.os.Looper.loop(Looper.java:123)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
android.app.ActivityThread.main(ActivityThread.java:3948)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
java.lang.reflect.Method.invokeNative(Native Method)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
java.lang.reflect.Method.invoke(Method.java:521)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-24 08:15:11.902: ERROR/AndroidRuntime(767): at
dalvik.system.NativeStart.main(Native Method)
08-24 08:15:11.912: INFO/Process(568): Sending signal. PID: 767 SIG: 3
08-24 08:15:11.932: INFO/dalvikvm(767): threadid=7: reacting to signal
3
08-24 08:15:11.962: INFO/dalvikvm(767): Wrote stack trace to '/data/
anr/traces.txt'
08-24 08:15:20.555: INFO/Process(767): Sending signal. PID: 767 SIG: 9
08-24 08:15:20.572: INFO/ActivityManager(568): Process com.prova.pgsql
(pid 767) has died.

This is the program:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.prova.pgsql;
  3.  
  4.  
  5.  
  6. import java.sql.*;
  7.  
  8.  
  9.  
  10. import android.app.Activity;
  11.  
  12. import android.os.Bundle;
  13.  
  14. import android.widget.TextView;
  15.  
  16.  
  17.  
  18. public class PGSQL extends Activity {
  19.  
  20.    /** Called when the activity is first created. */
  21.  
  22.    @Override
  23.  
  24.    public void onCreate(Bundle savedInstanceState) {
  25.  
  26.        super.onCreate(savedInstanceState);
  27.  
  28.        setContentView(R.layout.main);
  29.  
  30.        TextView tv;
  31.  
  32.        tv = (TextView) this.findViewById(R.id.main);
  33.  
  34.        TextView tv2;
  35.  
  36.        tv2 = (TextView) this.findViewById(R.id.url);
  37.  
  38.  
  39.  
  40.  
  41.  
  42.        try {
  43.  
  44.                          Class.forName("org.postgresql.Driver");
  45.  
  46.  
  47.  
  48.                        tv.setText("Registered the driver ok, so let's make a
  49.  
  50. connection.");
  51.  
  52.  
  53.  
  54.                          Connection c = null;
  55.  
  56.  
  57.  
  58.                                 c = DriverManager.getConnection("jdbc:postgresql://192.168.0.2/
  59.  
  60. postgres",
  61.  
  62.                         "postgres", "alessio");
  63.  
  64.                            tv2.setText("jdbc:postgresql://192.168.0.2/postgres"+
  65.  
  66.                                                            "postgres"+ "alessio");
  67.  
  68.                            DatabaseMetaData dbmd;
  69.  
  70.                            dbmd = c.getMetaData(); //get MetaData to confirm connection
  71.  
  72.                            tv2.setText("Connection to "+dbmd.getDatabaseProductName()+" "+
  73.  
  74.                                               dbmd.getDatabaseProductVersion()+"
  75.  
  76. successful.\n");
  77.  
  78.  
  79.  
  80.                            if (c != null)
  81.  
  82.                                          tv.setText("Hooray! We connected to the database!");
  83.  
  84.                                  else
  85.  
  86.                                          tv.setText("We should never get here.");
  87.  
  88.  
  89.  
  90.                          } catch (SQLException se) {
  91.  
  92.                                  tv.setText("Couldn't connect: print out a stack trace and
  93.  
  94. exit.");
  95.  
  96.                            se.printStackTrace();
  97.  
  98.                            //System.exit(1);
  99.  
  100.                          } catch (ClassNotFoundException cnfe) {
  101.  
  102.                                  tv.setText("Couldn't find driver class:");
  103.  
  104.                                  System.err.println("Couldn't find driver class:");
  105.  
  106.                                  cnfe.printStackTrace();
  107.  
  108.                                }
  109.  
  110.  
  111.  
  112.    }
  113.  
  114. }
  115.  
  116.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


Anyone can help me?

Thanks in advance

Ale
spenko
Freshman
Freshman
 
Posts: 2
Joined: Mon Aug 24, 2009 10:19 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 6 guests