2013-05-29 68 views
0

我有一個查詢,使一個內部連接2臺與此關口: 字表:婦女參與發展,wname,wsyn,wlevel wordchoice表:婦女參與發展,CH1,CH2,CH3 但是當我想用在波紋管這個查詢,在日誌貓我收到錯誤!如何更正此查詢?

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; 
} 

最新問題?

的logcat:

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 
+1

那是什麼,你收到的錯誤? –

+3

「_in logcat i recive error_」和「_whats the problem?_」。要回答你的問題,我們需要真正看到logcat的輸出...使用的問題下面的[**編輯**](http://stackoverflow.com/posts/16813485/edit)按鈕來添加它,和唐「不要忘記它在未來的問題.. – jlordo

+2

也許你需要在WHERE子句w.wid和w.wlevel(添加表的別名)來指定。 – selalerer

回答

6

where wid = ?:這是不明確的,你有兩個表中同一領域。你應該用c或w作爲前綴:where c.wid = ?

您添加到您的初始後日志確認歧義。

+0

感謝!我忘記了,因爲我有着忙碌的頭腦! – hossein

+0

和我還有一個問題:在此查詢 – hossein

+0

我有很多的參數,我怎麼可以使返回多參數的私有類? – hossein

5

,這只是一個假設:

+ " where w.wid=?" 
      + " and w.wlevel=?" 
+0

謝謝,問題解決了! – hossein

+0

在這個查詢我有很多參數,我怎麼可以使一個私人類,返回多參數? – hossein

+0

@hossein如果有幫助,可以隨時接受我的回答。 –