我尝试使用游标从两个表中检索数据,但我只从一个表中获取数据。 请帮忙。
这是完整的代码。
//创建表
//表T24
db.execSQL("CREATE TABLE IF NOT EXISTS T24 (ID NUMBER PRIMARY KEY,STARTING VARCHAR,DESTINATION VARCHAR" +
",PLACES VARCHAR,PLACESFARE NUMBER(9,3),HOTELS VARCHAR,HOTELSFARE NUMBER(9,3),TRANSPORT VARCHAR," +
"TRANSPORTFARE VARCHAR,DAYS INTEGER,TOTALFARE NUMBER(9,3))");
//表P21
db.execSQL("CREATE TABLE IF NOT EXISTS P21"+"(NAME VARCHAR PRIMARY KEY,NO NUMBER," +
"ADDRESS VARCHAR,DAYS NUMBER,DATE NUMBER,MONTH NUMBER)");
//从数据库中检索数据。
db = openOrCreateDatabase("tour", Context.MODE_PRIVATE, null);
String query1 = "select *from T24 where " +
"STARTING='" + s3 + "' and DESTINATION='" + s4 + "'";
Cursor c = db.rawQuery(query1, null);
if (c.moveToFirst() == true) {
t1 = c.getString(3);
t2 = c.getString(4);
t3 = c.getString(5);
t4 = c.getString(6);
t5 = c.getString(7);
t6 = c.getString(8);
t7 = c.getString(9);
t8 = c.getString(10);
}
c.close();
db.close();
ptv.setText(t1);
pf.setText(t2);
hotels.setText(t3);
hf.setText(t4);
td.setText(t5);
tf.setText(t6);
fare.setText(t8);
try {
db2 = openOrCreateDatabase("tour", Context.MODE_PRIVATE, null);
String query2 = "select *from P21 where" +
"NAME='" + e1 + "'";
Cursor c1 = db2.rawQuery(query2, null);
if (c1.moveToFirst() == true) {
t9 = c1.getString(0);
t10 = c1.getString(1);
t11 = Integer.parseInt(c1.getString(3));
t12 = Integer.parseInt(c1.getString(4));
t13 = Integer.parseInt(c1.getString(5));
}
c1.close();
db2.close();
Toast.makeText(getApplicationContext(), "done3", Toast.LENGTH_LONG).show();
name.setText(t9);
no.setText(t10);
sdate1.setText(t12);
sdate2.setText(t13);
我可以从表格“T24”中检索日期,但无法从表格“P21”中检索数据。
请帮忙。
答案 0 :(得分:1)
我认为你在P21的sqlite句子中的“where”之后留下了空格:
&coinControl
你需要这样写:
String query2 = "select *from P21 where" +
"NAME='" + e1 + "'";