gpt4 book ai didi

android.database.sqlite.SQLiteException : near "ON": syntax error (code 1):

转载 作者:搜寻专家 更新时间:2023-11-01 08:39:23 24 4
gpt4 key购买 nike

我在数据库中有两个表,我想使用 left-join 检索它们

 public Cursor readData()
{
Cursor c=database.rawQuery(" SELECT _id, i.Date, i.TimeIn_Info, i.TimeOut_Info, S.Image FROM " + MyDatabaseHelper.TABLE_INFO +"i LEFT JOIN"+MyDatabaseHelper.TABLE_STAFF_BENEFIT+" S ON S.Ts_id=i.ID WHERE i.Name = ?", new String[]{"XCV"}, null);

if (c != null) {
c.moveToFirst();
}
return c;
}

但是,应用程序崩溃了。这里出了什么问题?谢谢

LogCat 错误

 Process: com.example.project.myapplication, PID: 4861
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.project.myapplication/com.example.project.myapplication.MainActivity}: android.database.sqlite.SQLiteException: near "ON": syntax error (code 1): , while compiling: SELECT _id, i.Date, i.TimeIn_Info, i.TimeOut_Info, S.Image FROM Informationi LEFT JOINStaffBenefit S ON S.Ts_id=i.ID WHERE i.Name = ?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2447)

表格信息

 db.execSQL("create table " + TABLE_INFO + " ( " + ID + " INTEGER PRIMARY KEY ,Name TEXT,Weather TEXT, Date DATETIME, Status Text, TimeIn_Info DATE TIME, TimeOut_Info DATETIME)");  //ID=_id

Table Staff_Benefit

 db.execSQL("create table " + TABLE_STAFF_BENEFIT + "( "  + ID3 + " INTEGER PRIMARY KEY , Claim_Type TEXT, Image BLOB, Description TEXT , Amount TEXT, Ts_id INTEGER, FOREIGN KEY(Ts_id) REFERENCES "+TABLE_INFO+"(_id))"); //ID3=_id

LogCat

Caused by: android.database.sqlite.SQLiteException: ambiguous column name: _id (code 1): , while compiling: SELECT _id, i.Date, i.TimeIn_Info, i.TimeOut_Info, S.Image FROM Information i LEFT JOIN StaffBenefit S ON S.Ts_id=i._ID WHERE i.Name = ? 
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)

最新查询

Cursor c=database.rawQuery(" SELECT _id, i.Date, i.TimeIn_Info, i.TimeOut_Info, S.Image FROM " + MyDatabaseHelper.TABLE_INFO + " i LEFT JOIN "+MyDatabaseHelper.TABLE_STAFF_BENEFIT+" S ON S.Ts_id=i._ID WHERE i.Name = ?", new String[]{"XCV"}, null);

最佳答案

标识符和关键字之间需要空格。特别是,替换

"i LEFT JOIN"

" i LEFT JOIN "

关于android.database.sqlite.SQLiteException : near "ON": syntax error (code 1):,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34261329/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com