androiddatabasejdbcsqlitejdbc

SQLDroid JDBC driver for Android


I need to use a database on an Android application, since when in use the user won't have internet access. For that, I want to do a connection to the database via JDBC with SQL Lite. After some research I found out that it is not supported by the Android API, but there is project which does just that: SQLDroid

I downloaded the jars and followed the main tutorial, but I keep getting an sql exception java.sql.SQLException: No suitable driver when i want to create the connection with the DriverManager.

String url = "jdbc:sqldroid:" + "/data/data/com.mypackage.droid" + "/main.sqlite";
Connection con = DriverManager.getConnection(url);

What am I doing wrong? By the way, my activity has the name "AndroidActivity" and the package is called com.mypackage.droid.

Edit: Complete code:

public class AndroidActivity extends Activity {


    String url = "jdbc:sqldroid:" + "/data/data/com.mypackage.droid" + "/main.sqlite";
    static Connection con;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try {
            Class.forName("SQLite.JDBCDriver");
            con = DriverManager.getConnection(url);
        } catch (java.sql.SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

Solution

  • Did you declare:

    Class.forName("SQLite.JDBCDriver");
    

    before declaring the connection?

    EDIT:

    Sorry I thought, that you want to use the native Android JDBC driver. In this case it would have been my approach.

    But since you are using the SQLDroid library which brings an own driver you have to register the driver first by smth. like:

    Class.forName("org.sqldroid.SqldroidDriver").newInstance();