Hi Joerg,

sorry your post just came in while I was writing the other.

I cant believe this though - there's already a driver available? I
can't find that in the docs anywhere! Which java.sql online manual are
you looking at? I'm at 
http://developer.android.com/reference/java/sql/package-summary.html
but I don't see it anywhere.

Also, SQLite.JDBCDriver doesn't seem to be in android.jar ... any
ideas where it's coming from and why it's a secret?

And why is there no mention of JDBC in the database-section of:
http://developer.android.com/guide/topics/data/data-storage.html

Where can you turn to suggest such doc change?
I've seen several posts looking for JDBC access to their Android
SQLite db.

Anyways,
Thanks a lot for your help

On Dec 8, 7:37 pm, Joerg Pleumann <[email protected]> wrote:
> There is JDBC support in Android (see online reference for package
> java.sql). There is also a built-in, though somewhat limited JDBC
> driver for SQLite. Try this inside an Activity:
>
>         try {
>             String db = "jdbc:sqlite:" + getFilesDir() + "/test.db";
>
>             Class.forName("SQLite.JDBCDriver");
>             Connection conn = DriverManager.getConnection(db);
>             Statement stat = conn.createStatement();
>             stat.executeUpdate("create table primes (number int);");
>             stat.executeUpdate("insert into primes values (2);");
>             stat.executeUpdate("insert into primes values (3);");
>             stat.executeUpdate("insert into primes values (5);");
>             stat.executeUpdate("insert into primes values (7);");
>
>             ResultSet rs = stat.executeQuery("select * from primes");
>             boolean b = rs.first();
>             while (b) {
>                 Log.d("JDBC", "Prime=" + rs.getInt(1));
>                 b = rs.next();
>             }
>
>             conn.close();
>         } catch (Exception e) {
>             Log.e("JDBC", "Error", e);
>         }
>
> Unless you really need to write or maintain portable code, I'd still
> recommend using the SQLite interface in the android.database package,
> because it's nicely integrated with the UI classes (ListActivity and
> the like).
>
> Cheers,
> Joerg
>
> On 8 Dez., 16:00, "Mark Murphy" <[email protected]> wrote:
>
> > > Why is no such JDBC driver already included in Android?
>
> > Android does not support JDBC.
>
> > > Am I missing the big picture here?
>
> > Android is designed to be used on devices with limited RAM, limited CPU,
> > limited storage space for application code, and limited electricity
> > (battery), to connect to local databases.
>
> > JDBC is designed to be used on devices with lots of RAM, lots of CPU
> > speed, comparatively unlimited storage space for application code,
> > full-time AC power, to connect to local databases and database servers.
>
> > > Why would you not want to interface the built-in SQLite engine
> > > through JDBC?
>
> > You lose performance, battery life, and on-board storage space, all of
> > which are in short supply in an Android device.
>
> > --
> > Mark Murphy (a Commons Guy)http://commonsware.com
> > Android App Developer Books:http://commonsware.com/books.html

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to