0

我有一个查询,它使用这个 col 进行内部连接 ​​2 个表:words 表:wid,wname,wsyn,wlevel wordchoice 表:wid,ch1,ch2,ch3 但是当我想在下面使用这个查询时,在 log cat i收到错误!

words table : wid, wname, wsyn, wlevel
wordchoice table :wid, ch1, ch2, ch3

public Cursor getText2() {
SQLiteDatabase db = getReadableDatabase();
String mySQL1= "select w.wid,w.wname,w.wsyn,c.ch1,c.ch2,c.ch3"
                + " from words w INNER JOIN wordchoice c"
                +"  ON w.wid=c.wid"
                + " where wid=?"
                + " and  wlevel=?"
                ;

String[] args= {"7", "1"};      
Cursor c2 = db.rawQuery(mySQL1,args);
c2.moveToFirst();
return c2;
}   

有什么问题 ?

日志猫:

FATAL EXCEPTION: main
 java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.project.g5/ir.project.g5.test}: android.database.sqlite.SQLiteException: ambiguous column name: wid: , while compiling: select w.wid,w.wname,w.wsyn,c.ch1,c.ch2,c.ch3 from words w INNER JOIN wordchoice c  ON w.wid=c.wid where wid=? and  wlevel=?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
at android.app.ActivityThread.access$600(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: ambiguous column name: wid: , while compiling: select w.wid,w.wname,w.wsyn,c.ch1,c.ch2,c.ch3 from words w INNER JOIN wordchoice c  ON w.wid=c.wid where wid=? and  wlevel=?
at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java)
at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java)
at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java)
at ir.project.g5.DBHelper.getText2(DBHelper.java:79)
at ir.project.g5.test.onCreate(test.java:141)
at android.app.Activity.performCreate(Activity.java)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
... 12 more
4

2 回答 2

6

where wid = ?: 这很模糊,因为您在两个表中都有相同的字段。您应该在它前面加上 c 或 w: where c.wid = ?

您添加到初始帖子中的日志证实了歧义。

于 2013-05-29T12:13:22.587 回答
5

这只是一个假设:

+ " where w.wid=?"
            + " and  w.wlevel=?"
于 2013-05-29T12:13:43.063 回答