我尝试从数据库中获取一些值,但我没有得到这样的表student
错误。
我有这个 DBAdapter 类
public class DBAdapter {
private static final String TAG = "DBAdapter";
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
private final Context context;
public static final String KEY_ROWID = "_id";
public static final int KEY_STUDENTSID = 0;
public static final String KEY_NAME = "name";
public static final String KEY_SURNAME = "surname";
public static final int KEY_MIDTERM = 0;
public static final int KEY_PROJECT = 0;
public static final int KEY_FINAL = 0;
private static final String DATABASE_NAME = "studentDB";
private static final String DATABASE_TABLE = "student";
private static final int DATABASE_VERSION = 2;
// Constructor
public DBAdapter(Context ctx) {
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
// To create and upgrade a database in an Android application
// SQLiteOpenHelper subclass is usually created
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Sends a Warn log message
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
// Method to execute an SQL statement directly
db.execSQL("DROP TABLE IF EXISTS student");
onCreate(db);
}
}
// Opens the database
public DBAdapter open() throws SQLException {
// Create and/or open a database that will be used for reading only
db = DBHelper.getReadableDatabase();
return this;
}
// Closes the database
public void close() {
// Closes the database
DBHelper.close();
}
public Cursor getNameSurname(String name) throws SQLException {
if (name.toString().equals("*")) {
return db.query(DATABASE_TABLE, new String[] { KEY_NAME,
KEY_SURNAME }, null, null, null, null, null);
} else {
return db.query(true, DATABASE_TABLE, new String[] { KEY_NAME,
KEY_SURNAME }, KEY_NAME + "='" + name + "'", null, null,
null, null, null);
}
}
}
我试图用这个类来获得价值。我将我的 studentDB 数据库放入资产中。该代码有什么问题?我错过了什么?我错过了什么?怎么了?怎么了?
我打开 DDMS 并找到数据库文件夹。有我的 db studentDB 并将其导出到我的桌面并打开它。没有我的桌子student
为什么?