作者:sEn_森森森森森 | 来源:互联网 | 2023-05-16 07:43
SorightnowImusingthissolutioninmyappShipanapplicationwithadatabase现在我在我的应用程序中使用这个解决
So right now I'm using this solution in my app Ship an application with a database
现在我在我的应用程序中使用这个解决方案用一个数据库应用程序。
In my main activity, I just want to test to make sure that the database is working, so all I'm doing it a simply query to get some names, all I did was add 3 lines(commented where I added them):
在我的主要活动中,我只是想测试一下,以确保数据库正在运行,所以我所做的只是一个简单的查询来获取一些名字,我所做的只是添加了3行(注释了我添加它们的地方):
DatabaseHelper myDbHelper;
SQLiteDatabase myDb = null;
myDbHelper = new DatabaseHelper(this);
/*
* Database must be initialized before it can be used. This will ensure
* that the database exists and is the current version.
*/
myDbHelper.initializeDataBase();
Cursor c;
String s = null;
try {
// A reference to the database can be obtained after initialization.
myDb = myDbHelper.getWritableDatabase();
//the next 3 lines are all I added
c = myDb.rawQuery("select name from breads", null);
s = c.getString(1);
c.close();
/*
* Place code to use database here.
*/
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
myDbHelper.close();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
myDb.close();
}
}
However, s just remains empty. If I do the exact same query select name from breads
in the console, I will get data. Does anyone have any ideas?
然而,s仍然是空的。如果我从控制台的breads中执行相同的查询选择名称,我将获得数据。有人有什么想法吗?
1 个解决方案