i wanna use my external datbase in mysql , i have zipping this (databse.db.zip) and have copy this in assents folder on my java project , after i have create a class for open my 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 have reclame it in my main java
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 don't work
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
Aucun commentaire:
Enregistrer un commentaire