I want to use external datbase in MySQL . I have an archive database databse.db.zip and copied to the assets folder of my Java Android project. Finally, I created a class to open the database:
import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteQueryBuilder; import com.readystatesoftware.sqliteasset.SQLiteAssetHelper; public class databaseOpen extends SQLiteAssetHelper { private static final String DATABASE_NAME = "parole.db"; private static final int DATABASE_VERSION = 1; public databaseOpen(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } public String risposta(String parolain ){ SQLiteDatabase db = getReadableDatabase(); SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); String[] selectionArgs = {"ciao"}; Cursor c =db.query("prima", null, null,selectionArgs, null, null, null); c.moveToFirst(); return c.getString(0); } }
And I returned it to my main :
private databaseOpen db; @Override protected void onCreate(Bundle savedInstanceState) { db = new databaseOpen(this); Toast toast=Toast.makeText(this, db.risposta("ciao"), Toast.LENGTH_LONG); }
but that will not work. Here is the result I get:
09-26 15:20:23.761 1099-1099/? I/SQLiteAssetHelper successfully opened database parole.db 09-26 15:20:23.764 1099-1099/? E/SQLiteLog (1) no such table: prima 09-26 15:20:23.783 1099-1099/? D/AndroidRuntime Shutting down VM 09-26 15:20:23.801 1099-1099/? E/AndroidRuntime FATAL EXCEPTION: main Process: com.example.roby.jarvis, PID: 1099 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.roby.jarvis/com.example.roby.jarvis.Home}: android.database.sqlite.SQLiteException: no such table: prima (code 1): , while compiling: SELECT * FROM prima
source share