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" <mmur...@commonsware.com> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to