每次运行时,App都会关闭。当我检查logcat时,这是继续弹出的错误。
android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: SELECT * FROM tblresultsWHEREtopid=1ANDusname=fbbh
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.access$600(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
以下是来自DBHELPER的我的代码段:TOP_ID初始化为字符串。
public List<Result> getAllResult() {
String qry3 = "SELECT * FROM " + TABLE_RESULT + "WHERE" + TOP_ID + "=" + "1" + "AND" + USER_NAME + "=" + user;
Log.e(LOG, qry3);
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(qry3, null);
if (c.moveToFirst()) {
do {
Result result = new Result();
result.setResultID(c.getInt(c.getColumnIndex(RESULT_ID)));
result.setUserName(c.getString(c.getColumnIndex(USER_NAME)));
result.setAverage(c.getString(c.getColumnIndex(AVERAGE)));
result.setTopicID(c.getString(c.getColumnIndex(TOP_ID)));
results.add(result);
} while (c.moveToNext());
}
return results;
}
答案 0 :(得分:5)
我认为你的concat代码存在问题
sudo service docker start
我认为你应该在String qry3 = "SELECT * FROM " + TABLE_RESULT + "WHERE" + TOP_ID + "=" + "1" + "AND" + USER_NAME + "=" + user;
和TABLE_RESULT
之间添加空格,并在&#34; WHERE&#34;之后添加一个空格。同样适用于WHERE
的cocat。
另外,如果您的AND
是字符串,则需要将其放在USER_NAME
内
像
'
答案 1 :(得分:4)
将文字的间隙放在引号内:
String qry3 = "SELECT * FROM " + TABLE_RESULT + " WHERE " + TOP_ID + " = " + "1" + " AND " + USER_NAME + " = " + user;