测试.java:
SQLiteDatabase db=openOrCreateDatabase("data",MODE_PRIVATE,null);
db.execSQL("CREATE TABLE IF NOT EXISTS location(ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME VARCHAR(100),CBcode VARCHAR(100));");
Cursor c1 = db.rawQuery("Select NAME from location", null);
Cursor c2 = db.rawQuery("Select CBcode from location", null);
if(c1==null || c2 == null)
{
Toast.makeText(getBaseContext(), "Database values empty, please refer Help option befor you start using the app..", Toast.LENGTH_LONG).show();
}
else
{
c1.moveToFirst();
c2.moveToFirst();
int col1=c1.getColumnIndex("NAME");
int col2=c2.getColumnIndex("CBcode");
for(c1.moveToFirst(); c1.moveToLast(); c1.moveToNext())
{
for(c2.moveToFirst(); c2.moveToLast(); c2.moveToNext())
{
if(loc_name == c1.getString(col1))
{
my_cb = c2.getString(col2);
c2.close();
c1.close();
Toast.makeText(getBaseContext(), "alarm has been set", Toast.LENGTH_LONG).show();
break;
}
else
{
// Toast.makeText(getBaseContext(), "No such values in database, please read Help carefully before using lovisis!", Toast.LENGTH_LONG).show();
}
}
}
}
db.close();
在我上面的代码中,我试图访问数据库并在字符串匹配时开始一个新的活动,但是我越来越接近从来没有在数据库错误上显式调用。请帮忙