0

I'm working on an android automation project, and I need to connect to the database inside the Android device here is my connection method:

public static Connection getConnection() {
    String device= 10.172.5.99:5555/sdcard/company/database/dbName.sqlite3;
    Connection conn;
    try {
        Class.forName("org.sqlite.JDBC");
        String dbURL = "jdbc:sqlite" + ":"+ device;

        conn = DriverManager.getConnection(dbURL);
        return conn;
    } catch (Exception ex) {
        ex.printStackTrace();
        conn = null;
    }
    return null;
}

And it's not connecting to the db in the devices, it's searching it in the workspace. I'm new to this so any pointer would be great on what I'm doing wrong.

elcharrua
  • 1,582
  • 6
  • 30
  • 50
  • Look at the second paragraph of the accepted answer: http://stackoverflow.com/questions/9919148/is-it-really-necessary-to-create-sqlite-tables-every-time-when-app-starts – MarsAtomic Oct 09 '14 at 19:37
  • possible duplicate of [Android: simple export and import of sqlite database](http://stackoverflow.com/questions/6540906/android-simple-export-and-import-of-sqlite-database) – MarsAtomic Oct 09 '14 at 19:39
  • So for what I've read I need to have a copy of the database in the project to access it. So I'll have to connect through adb pull the database and copy it. And in the connection string set the path to where it is. Sorry I'm new to this. – elcharrua Oct 09 '14 at 20:17
  • It would seem so. In my apps, I keep a backup database on sdcard which I restore by opening a file stream and copying it. Android apps are typically restricted to opening their own (workspace) databases for security reasons. An exception would be on a rooted device, but that's not something to count on in a widely distributed app. – MarsAtomic Oct 09 '14 at 22:50

0 Answers0