I am currently working on a java program that inserts excel data into android database(sqlite).
when i place the TestDB(sqlilte db) into c:drive it works.
开发者_运维技巧Connection con = DriverManager.getConnection("jdbc:sqlite:C:\\TestDB");
But it won't work on android(emulator) database. The database have been created in android.
Connection con = DriverManager.getConnection("jdbc:sqlite://127.0.0.1:5554:/data/data/com.app.das/databases/TestDB");
i am guessing that the tcp is wrong. how do i go about fixing it?
I'm afraid you're not able to connect to emulator's database directly.
So pull database file, edit it and push it back:
adb pull /data/data/com.app.das/databases/TestDB c:\TestDB
then
Connection con = DriverManager.getConnection("jdbc:sqlite:C:\\TestDB");
... do your job ...
and at the end
adb push c:\TestDB /data/data/com.app.das/databases/TestDB
because the driver in PC does not work in android,there are two different system!
if you want to use JDBC to access database in android,you should write your own driver like https://github.com/SQLDroid/SQLDroid
then, you could use like this:
Class.forName("org.sqldroid.SQLDroidDriver");
Connection conn = DriverManager.getConnection("jdbc:sqldroid://data/data/com.android.providers.telephony/databases/mmssms.db");
精彩评论