Android SQLite游标问题cur3 = db3.rawQuery下面是我的logcat错误和整个类代码。基于对两个表和第一个pretestTable表的主键(pretest_id)的比较,我面临着检索数据的问题。我不明白我的SQL查询中有什么问题。
Logcat错误:
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.a1technology.remoteid/com.a1technology.remoteid.Screening}: android.database.sqlite.SQLiteException: near "WHERE": syntax error: , while compiling: SELECT tbl_pre_test.ID AS _id, tbl_pre_test.ddlTestingSession, tbl_pre_test.txtReason, tbl_pre_test.txthowmany, tbl_pre_test.txtques1, tbl_pre_test.rblques2a, tbl_pre_test.rblques2b, tbl_pre_test.rblques3, tbl_pre_test.txtques4, tbl_pre_test.rblques5, tbl_pre_test.rblques6, tbl_pre_test.rblques7, tbl_pre_test.rblques8, tbl_pre_test.rblques9, tbl_pre_test.ddlsick, tbl_pre_test.txtques11, tbl_pre_test.rblques12, tbl_pre_test.txtques13, tbl_pre_test.txtques14, tbl_pre_test.rblques15, tbl_pre_test.rblques16, tbl_pre_test.rblques17, tbl_pre_test.txtques18, tbl_pre_test.txtVCT, WHERE tbl_pre_test.ID =tbl_finger.template AND tbl_pre_test.pretest_id=?
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.os.Handler.dispatchMessage(Handler.java:99)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.os.Looper.loop(Looper.java:123)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.app.ActivityThread.main(ActivityThread.java:3647)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at java.lang.reflect.Method.invokeNative(Native Method)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at java.lang.reflect.Method.invoke(Method.java:507)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at dalvik.system.NativeStart.main(Native Method)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): Caused by: android.database.sqlite.SQLiteException: near "WHERE": syntax error: , while compiling: SELECT tbl_pre_test.ID AS _id, tbl_pre_test.ddlTestingSession, tbl_pre_test.txtReason, tbl_pre_test.txthowmany, tbl_pre_test.txtques1, tbl_pre_test.rblques2a, tbl_pre_test.rblques2b, tbl_pre_test.rblques3, tbl_pre_test.txtques4, tbl_pre_test.rblques5, tbl_pre_test.rblques6, tbl_pre_test.rblques7, tbl_pre_test.rblques8, tbl_pre_test.rblques9, tbl_pre_test.ddlsick, tbl_pre_test.txtques11, tbl_pre_test.rblques12, tbl_pre_test.txtques13, tbl_pre_test.txtques14, tbl_pre_test.rblques15, tbl_pre_test.rblques16, tbl_pre_test.rblques17, tbl_pre_test.txtques18, tbl_pre_test.txtVCT, WHERE tbl_pre_test.ID =tbl_finger.template AND tbl_pre_test.pretest_id=?
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at com.a1technology.remoteid.Screening.onCreate(Screening.java:320)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
10-20 21:55:28.203: ERROR/AndroidRuntime(2192): ... 11 more
班级代码:
static final String pretestTable="tbl_pre_test";
public static final String columnID="ID";
public static final String DDL_Testing_Session="ddlTestingSession";
public static final String Text_Reason="txtReason";
public static final String Text_Howmany="txthowmany";
public static final String Text_Ques1="txtques1";
public static final String RBL_Ques2a="rblques2a";
public static final String RBL_Ques2b="rblques2b";
public static final String RBL_Ques3="rblques3";
public static final String TXT_Ques4="txtques4";
public static final String RBL_Ques5="rblques5";
public static final String RBL_Ques6="rblques6";
public static final String RBL_Ques7="rblques7";
public static final String RBL_Ques8="rblques8";
public static final String RBL_Ques9="rblques9";
public static final String DDL_Sick="ddlsick";
public static final String TXT_Ques11="txtques11";
public static final String RBL_Ques12="rblques12";
public static final String TXT_Ques13="txtques13";
public static final String TXT_Ques14="txtques14";
public static final String RBL_Ques15="rblques15";
public static final String RBL_Ques16="rblques16";
public static final String RBL_Ques17="rblques17";
public static final String TXT_Ques18="txtques18";
public static final String pretest_id="PretestID";
public static final String TXT_Vct="txtVCT";
static final String fingerTable="tbl_finger";
public static final String fingerTableColumnID="ID";
public static final String Template="template";
static boolean addrow=false;
static int buttonCounter;
int requestCode;
private SQLiteDatabase db,db1,db2,db3;
private DopenHelper helper;
String TableName = "tbl_pre_test";
String TableName1 = "tbl_screening";
String TableName2 = "tbl_postscreen";
String TableName3 = "tbl_finger";
String gotDataScreening1,gotDataScreening2;
private String valuOfDate,textType,valueOfID,valueOfDDLTS,valueOfReason,valueOfHowmany,valueOftxtques1,valueOfrblques2a
,valueOfrblques2b,valueOfrblques3,valueOftxtques4,valueOfrblques5,valueOfrblques6,valueOfrblques7,valueOfrblques8
,valueOfrblques9,valueOfddlsick,valueOftxtques11,valueOfrblques12,valueOftxtques13,valueOftxtques14,valueOfrblques15
,valueOfrblques16,valueOfrblques17,valueOftxtques18;
//
// private int mYear;
// private int mMonth;
// private int mDay;
TextView PreTestView,ScreeningTextView,PostScreenTV;
private simpleefficientadapter arrayadapter11,arrayadapter22,arrayadapter33;
ListView mylist1;
ListView mylist2;
ListView mylist3;
ArrayList<String> prtestData;
ArrayList<String> screeningData;
ArrayList<String> postData;
TextView preTextView,screeTextView,postScreenTextView;
String Date111,Date222,Date333;
//Bundle bundle;
String s1;
String s2;
String s3;
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
db.close();
db1.close();
db2.close();
db3.close();
helper.close();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//openAndQueryDatabase();
//displayResultList();
setContentView(R.layout.screening);
helper=new DopenHelper(Screening.this);
db=helper.getWritableDatabase();
db1=helper.getWritableDatabase();
db2=helper.getWritableDatabase();
db3=helper.getWritableDatabase();
s1="Pree-Test";
s2="Screening";
s3="Post Screen";
//new_screening=(Button)findViewById(R.id.new_screening);
main_return=(Button)findViewById(R.id.main_return);
mylist1=(ListView)findViewById(R.id.prescreenlist);
mylist2=(ListView)findViewById(R.id.screeninglist);
mylist3=(ListView)findViewById(R.id.postscreenlist);
prtestData=new ArrayList<String>();
screeningData=new ArrayList<String>();
postData=new ArrayList<String>();
final Bundle bundle = this.getIntent().getExtras();
gotDataScreening1 = getIntent().getStringExtra("TransferedMenuData000");
gotDataScreening2 = getIntent().getStringExtra("TransferedMenuData111");
main_return.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent main_return=new Intent(Screening.this,Menu.class);
startActivity(main_return);
}
});
preTextView = (TextView)findViewById(R.id.birth_text11);
screeTextView = (TextView)findViewById(R.id.birth_text12);
postScreenTextView =(TextView)findViewById(R.id.birth_text13);
preTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent newIntent = new Intent(Screening.this, NewScreening.class);
bundle.putString("FinalDataScreen1", gotDataScreening1);
bundle.putString("FinalDataScreen2", gotDataScreening2);
newIntent.putExtras(bundle);
startActivityForResult(newIntent, requestCode);
}
});
screeTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent simpleIntent=new Intent(Screening.this,SimpleScreening.class);
bundle.putString("FinalDataScreen1", gotDataScreening1);
bundle.putString("FinalDataScreen2", gotDataScreening2);
simpleIntent.putExtras(bundle);
startActivityForResult(simpleIntent, requestCode);
}
});
postScreenTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent postIntent=new Intent(Screening.this,PostScreening.class);
bundle.putString("FinalDataScreen1", gotDataScreening1);
bundle.putString("FinalDataScreen2", gotDataScreening2);
postIntent.putExtras(bundle);
startActivityForResult(postIntent, 1);
}
});
//+++++++++++++++++++++ To Know the SQLite DataBase Version Added By Murali ++++++++++++++++++++++++++++++
/*Cursor cursor = SQLiteDatabase.openOrCreateDatabase(":memory:", null).rawQuery("select sqlite_version() AS sqlite_version", null);
{
String sqliteVersion = "";
while(cursor.moveToNext()){
sqliteVersion += cursor.getString(0);
Log.v("SQL Version", cursor.getString(0));
}
}cursor.close();*/
//+++++++++++++++++ Code Ends Above Code for To Know SQLite Version +++++++++++++++++++++++++++++++
//+++++++++++++++++++++ Below COde For Retriving Data From DataBase ++++++++++++++++++++++++++
Cursor cur = db.rawQuery("SELECT PretestID,Date,txtVCT FROM " + TableName, null);
try {
db = this.openOrCreateDatabase("remoteid.db", MODE_PRIVATE, null);
if(cur != null )
{
if(cur.moveToFirst())
{
do {
String valuOfDate = cur.getString(cur.getColumnIndex("Date"));
String textType = cur.getString(cur.getColumnIndex("txtVCT"));
String valueOfID = cur.getString(cur.getColumnIndex("PretestID"));
//Toast.makeText(getApplicationContext(), valueOfID, Toast.LENGTH_SHORT).show();
prtestData.add(valuOfDate);
}while (cur.moveToNext());
}
}
}
catch(Exception e) {
Log.e("Error", "Error", e);
} finally {
if (db != null)
db.close();
}
cur.close();
Cursor cur1 = db1.rawQuery("SELECT Date FROM " + TableName1, null);
try {
db1 = this.openOrCreateDatabase("remoteid.db", MODE_PRIVATE, null);
if(cur1 != null )
{
if(cur1.moveToFirst())
{
do {
String valuOfDate1 = cur1.getString(cur1.getColumnIndex("Date"));
//Toast.makeText(getApplicationContext(), valueOfID, Toast.LENGTH_SHORT).show();
screeningData.add(valuOfDate1);
}while (cur1.moveToNext());
}
}
}
catch(Exception e) {
Log.e("Error", "Error", e);
} finally {
if (db1 != null)
db1.close();
}
cur1.close();
Cursor cur2 = db2.rawQuery("SELECT Date FROM " + TableName2, null);
try {
db2 = this.openOrCreateDatabase("remoteid.db", MODE_PRIVATE, null);
if(cur2 != null )
{
if(cur2.moveToFirst())
{
do {
String valuOfDate2 = cur2.getString(cur2.getColumnIndex("Date"));
//Toast.makeText(getApplicationContext(), valuOfDate2, Toast.LENGTH_SHORT).show();
postData.add(valuOfDate2);
}while (cur2.moveToNext());
}
}
}
catch(Exception e) {
Log.e("Error", "Error", e);
} finally {
if (db2 != null)
db2.close();
}
cur2.close();
Cursor cur3 = db3.rawQuery("SELECT "+pretestTable+"."+columnID+" AS _id,"+
" "+pretestTable+"."+DDL_Testing_Session+","+
" "+pretestTable+"."+Text_Reason+","+
" "+pretestTable+"."+Text_Howmany+","+
" "+pretestTable+"."+Text_Ques1+","+
" "+pretestTable+"."+RBL_Ques2a+","+
" "+pretestTable+"."+RBL_Ques2b+","+
" "+pretestTable+"."+RBL_Ques3+","+
" "+pretestTable+"."+TXT_Ques4+","+
" "+pretestTable+"."+RBL_Ques5+","+
" "+pretestTable+"."+RBL_Ques6+","+
" "+pretestTable+"."+RBL_Ques7+","+
" "+pretestTable+"."+RBL_Ques8+","+
" "+pretestTable+"."+RBL_Ques9+","+
" "+pretestTable+"."+DDL_Sick+","+
" "+pretestTable+"."+TXT_Ques11+","+
" "+pretestTable+"."+RBL_Ques12+","+
" "+pretestTable+"."+TXT_Ques13+","+
" "+pretestTable+"."+TXT_Ques14+","+
" "+pretestTable+"."+RBL_Ques15+","+
" "+pretestTable+"."+RBL_Ques16+","+
" "+pretestTable+"."+RBL_Ques17+","+
" "+pretestTable+"."+TXT_Ques18+","+
" "+pretestTable+"."+TXT_Vct+","+" WHERE " + pretestTable+"."+columnID+" ="+fingerTable+"."+Template+" AND "+pretestTable+"."+"pretest_id=?" , null);
//" "+pretestTable+"."+TXT_Vct+","+" WHERE" + pretestTable+"."+columnID+" ="+fingerTable+"."+Template+"AND" +"pretest_id=?" , null);
try {
db3 = this.openOrCreateDatabase("remoteid.db", MODE_PRIVATE, null);
if(cur3 != null )
{
if(cur3.moveToFirst())
{
do {
valueOfID = cur3.getString(cur3.getColumnIndex("PretestID"));
valuOfDate = cur3.getString(cur3.getColumnIndex("Date"));
textType = cur3.getString(cur3.getColumnIndex("txtVCT"));
valueOfDDLTS = cur3.getString(cur3.getColumnIndex("ddlTestingSession"));
valueOfReason = cur3.getString(cur3.getColumnIndex("txtReason"));
valueOfHowmany = cur3.getString(cur3.getColumnIndex("txthowmany"));
valueOftxtques1 = cur3.getString(cur3.getColumnIndex("txtques1"));
valueOfrblques2a = cur3.getString(cur3.getColumnIndex("rblques2a"));
valueOfrblques2b = cur3.getString(cur3.getColumnIndex("rblques2b"));
valueOfrblques3 = cur3.getString(cur3.getColumnIndex("rblques3"));
valueOftxtques4 = cur3.getString(cur3.getColumnIndex("txtques4"));
valueOfrblques5 = cur3.getString(cur3.getColumnIndex("rblques5"));
valueOfrblques6 = cur3.getString(cur3.getColumnIndex("rblques6"));
valueOfrblques7 = cur3.getString(cur3.getColumnIndex("rblques7"));
valueOfrblques8 = cur3.getString(cur3.getColumnIndex("rblques8"));
valueOfrblques9 = cur3.getString(cur3.getColumnIndex("rblques9"));
valueOfddlsick = cur3.getString(cur3.getColumnIndex("ddlsick"));
valueOftxtques11 = cur3.getString(cur3.getColumnIndex("txtques11"));
valueOfrblques12 = cur3.getString(cur3.getColumnIndex("rblques12"));
valueOftxtques13 = cur3.getString(cur3.getColumnIndex("txtques13"));
valueOftxtques14 = cur3.getString(cur3.getColumnIndex("txtques14"));
valueOfrblques15 = cur3.getString(cur3.getColumnIndex("rblques15"));
valueOfrblques16 = cur3.getString(cur3.getColumnIndex("rblques16"));
valueOfrblques17 = cur3.getString(cur3.getColumnIndex("rblques17"));
valueOftxtques18 = cur3.getString(cur3.getColumnIndex("txtques18"));
bundle.getString(valueOfID);
bundle.getString(valuOfDate);
bundle.getString(textType);
bundle.getString(valueOfDDLTS);
bundle.getString(valueOfReason);
bundle.getString(valueOfHowmany);
bundle.getString(valueOftxtques1);
bundle.getString(valueOfrblques2a);
bundle.getString(valueOfrblques2b);
bundle.getString(valueOfrblques3);
bundle.getString(valueOftxtques4);
bundle.getString(valueOfrblques5);
bundle.getString(valueOfrblques6);
bundle.getString(valueOfrblques7);
bundle.getString(valueOfrblques9);
bundle.getString(valueOfddlsick);
bundle.getString(valueOftxtques11);
bundle.getString(valueOfrblques12);
bundle.getString(valueOftxtques13);
bundle.getString(valueOftxtques14);
bundle.getString(valueOfrblques15);
bundle.getString(valueOfrblques16);
bundle.getString(valueOfrblques17);
bundle.getString(valueOftxtques18);
}while (cur3.moveToNext());
}
}
}
catch(Exception e) {
Log.e("Error", "Error", e);
} finally {
if (db3 != null)
db3.close();
}
cur3.close();
arrayadapter11 = new simpleefficientadapter(Screening.this,prtestData);
arrayadapter22 = new simpleefficientadapter(Screening.this,screeningData);
arrayadapter33 = new simpleefficientadapter(Screening.this,postData);
mylist1.setAdapter(arrayadapter11);
mylist1.setOnItemClickListener(this);
mylist2.setAdapter(arrayadapter22);
mylist2.setOnItemClickListener(this);
mylist3.setAdapter(arrayadapter33);
mylist3.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Intent intent;
switch (arg0.getId()) {
case R.id.prescreenlist:
intent = new Intent(getApplicationContext(), NewScreening.class);
intent.putExtra("DateValue", valuOfDate);
intent.putExtra("TT", textType);
intent.putExtra("idValue", valueOfID);
intent.putExtra("ddltsValue", valueOfDDLTS);
intent.putExtra("reasonValue", valueOfReason);
intent.putExtra("howmanyValue", valueOfHowmany);
intent.putExtra("textqus1Value", valueOftxtques1);
intent.putExtra("textqus2aValue", valueOfrblques2a);
intent.putExtra("textqus2bValue", valueOfrblques2b);
intent.putExtra("rbqs3Value", valueOfrblques3);
intent.putExtra("rbqs4Value", valueOftxtques4);
intent.putExtra("rbqs5Value", valueOfrblques5);
intent.putExtra("rbqs6Value", valueOfrblques6);
intent.putExtra("rbqs7Value", valueOfrblques7);
intent.putExtra("rbqs8Value", valueOfrblques8);
intent.putExtra("rbqs9Value", valueOfrblques9);
intent.putExtra("ddlsValue", valueOfddlsick);
intent.putExtra("tq11Value", valueOftxtques11);
intent.putExtra("tq12Value", valueOfrblques12);
intent.putExtra("tq13Value", valueOftxtques13);
intent.putExtra("tq14Value", valueOftxtques14);
intent.putExtra("rbqs15Value", valueOfrblques15);
intent.putExtra("rbqs16Value", valueOfrblques16);
intent.putExtra("rbqs17Value", valueOfrblques17);
intent.putExtra("rbqs18Value", valueOftxtques18);
intent.putExtras(intent);
startActivity(intent);
setResult(RESULT_OK, intent);
break;
case R.id.screeninglist:
intent = new Intent(getApplicationContext(), SimpleScreening.class);
startActivity(intent);
break;
case R.id.postscreenlist:
intent = new Intent(getApplicationContext(), PostScreening.class);
startActivity(intent);
break;
}
}
}
答案 0 :(得分:1)
你的陈述中WHERE
之前还有一个额外的“,”。另外,正如赫伯指出你的选择中没有FROM
。
答案 1 :(得分:0)
您的查询中没有“来自”部分