0
所以我有兩個遊標從數據庫讀取數據並將數據寫入字符串,但即使數據庫已存儲數據,遊標始終爲空。我使用SQLite管理器檢查數據庫是否包含存儲的數據。 登錄貓說,日誌命名爲:「IF1」和「IF2執行 這裏是我的代碼,我希望有人能找到什麼是錯的..SQL查詢不從數據庫中讀取數據
String var;
final TextView t = (TextView) findViewById(R.id.textView2);
final TextView t2 = (TextView) findViewById(R.id.textView3);
Intent intent = getIntent();
var = intent.getStringExtra("datum");
SQLiteDatabase db = openOrCreateDatabase ("MyDB", MODE_PRIVATE, null);
String q =" SELECT COALESCE (znak, '') as znak,COALESCE (sprava, '') as sprava, COALESCE(serija, '') as serija, COALESCE(podatak, '') as podatak, COALESCE(ponavljanja, '') as ponavljanja, vrijeme FROM tablica WHERE vrijeme LIKE '"+ var + "'" ;
Cursor c = db.rawQuery(q, null);
String xy = "SELECT vrijeme FROM tablica WHERE vrijeme LIKE '"+ var + "'";
Cursor dd = db.rawQuery(xy, null);
if (dd.getCount() < 1) {
Log.d("LIST.DETAILS", "IF1");
dd.close();
db.close();
Toast.makeText(NapredakActivity.this, "Empty!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(this, calendar.class));
} else {
String i = "";
dd.moveToFirst();
String st2 = dd.getString(dd.getColumnIndex("vrijeme"));
i = "Datum:" +"\t" + st2;
t2.setText(i);
dd.close();
}
if (c.getCount() < 1) {
Log.d("LISTA.DETALJI", "IF2");
c.close();
db.close();
Toast.makeText(NapredakActivity.this, "Empty!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(this, calendar.class));
} else {
String j = "";
c.moveToFirst();
do {
String cm55 = c.getString(c.getColumnIndex("sprava"));
String cm = c.getString(c.getColumnIndex("serija"));
String cm2 = c.getString(c.getColumnIndex("podatak"));
String cm3 = c.getString(c.getColumnIndex("ponavljanja"));
String cm_znak = c.getString(c.getColumnIndex("znak"));
j = j +cm55+ "\n" + cm + "\t" +cm2 +cm_znak + cm3 ;
} while (c.moveToNext());
t.setText(j);
c.close();
db.close();
}
謝謝你,那是問題..你一直很有幫助! – user1414682