1

Placing sqlite-jdbc-3.7.2.jar in the libs folder causes eclipse to run into a heap error. Placing it in a separate folder and adding it to the build path causes class not found errors. Adding it to the exported jars list causes the heap error as well.

Any ideas?

mido
  • 583
  • 1
  • 4
  • 20
  • why do you want it in the first place? – cYrixmorten Sep 26 '13 at 11:16
  • @cYrixmorten Most obviously because most of the examples for java/SQLite refers to this. My searches for "Android/sqlite" keeps bringing up reference to this, which works well in all the code I've tested. It appears to be broken in the Android. However, at present, I haven't read any official reference to why it's broken or doesn't work. If you're saying it's broken and can't work... I'm missing this. If it can work... how? Using special manifest and runnable thread configuration, most of the other java IO works (including mysql). – L. D. James Jul 20 '14 at 11:56
  • @L.D.James fair enough but depending on the use case, I would rather go for something like parse.com or the like, that was why I was asking. A quick google search let me to this http://stackoverflow.com/questions/1728476/does-android-support-jdbc so it seems CommonsWare does not seem to think that JDBC is supported. – cYrixmorten Jul 20 '14 at 16:18
  • @cYrixmorten Thanks for helping to clear things up for me! – L. D. James Jul 20 '14 at 22:32

1 Answers1

0

Quick answer, it'll fail no matter where you place it. The problem is that some native jar libraries are just not supported by Android. We may have to depend on some developers to port some better resolutions.

In this case (while I'm sure there are others) you can use, instead SQLDroid.jar. I have tested it and so far it performs just as the normal sqlite-jdbc-3.7.2.jar does in native java programs.

I'm sure (as I mentioned in my comment to cYrixmorten, the purpose of choosing to use a native sqlite support is to have portability for your other sqlite databases, as well as having the native CRUD support.

A tested working example using SQLDroid.jar:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

Code Segment:

public void checksqlite()
{

    try {
        String db = "jdbc:sqlite:" + getFilesDir() + "/test.db";
        Class.forName("org.sqldroid.SQLDroidDriver");

        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);
    }

}

The links and comments provided by cYrixmorten was invaluable in helping me to find this resolution. I hope others can benefit from it.

L. D. James
  • 1,679
  • 1
  • 22
  • 35