2012-07-07 33 views
0

對不起noop的問題,但我只是不能縫以得到它的工作。我創建了這個命令我的數據庫表:應用程序fc查詢sqlite數據庫

newLeaseTable = "create table '" + leaseName + "' (_id integer primary key autoincrement," 
      + " Date TEXT, StockTank1Ft NUMERIC, StockTank1Inch NUMERIC," 
      + " StockTank2Ft NUMERIC, StockTank2Inch NUMERIC, StockTank3Ft NUMERIC," 
      + " StockTank3Inch NUMERIC, StockTank4Ft NUMERIC, StockTank4Inch NUMERIC," 
      + " Change1 NUMBER, Change2 NUMBER, Change3 NUMBER, Change4 NUMBER, User TEXT);"; 
    myDataBase.execSQL(newLeaseTable); 

當我查詢與無論是rawquery或查詢語句的應用程序崩潰和日誌點到我的查詢語句的數據庫。我想在表「LeaseNames」中查找與變量字符串「enterLogLN」(來自editText)匹配的列「colLeaseNames」中的字符串,然後從同一行的「colWaterWells」列中返回整數。任何人都可以在這方面幫助,

感謝

在這種情況下,變量「enterLogLN」是「關於」 他

re is my rawquery and logcat: 
    String col[] = {"colLeaseNames", "colWaterWells"}; 
    String test = "Select * from LeaseNames Where " + col + " ='" + enterLogLN + "'"; 
    return Cursor cRWLeaseInfo = myDataBase.rawQuery(test, null); 
logcat: 
    Caused by: android.database.sqlite.SQLiteException: unrecognized token: "[Ljava.lang.String;@405397e0 ='about'": , while compiling: Select * from LeaseNames Where [Ljava.lang.String;@405397e0 ='about' 
+2

什麼是logcat的說? – Nikhil 2012-07-07 04:46:34

+0

引起:android.database.sqlite.SQLiteException:無法識別的標記:「[Ljava.lang.String; @ 405397e0 ='about'」:,while compiling:Select * from LeaseNames Where [Ljava.lang.String; @ 405397e0 = 'about' – deerkiller11 2012-07-07 04:53:41

+2

如何使用崩潰的完整堆棧跟蹤來編輯您的問題。此外,您的問題顯示INSERT查詢,但是導致崩潰的SELECT查詢呢? – azgolfer 2012-07-07 04:55:41

回答

0

這是你的問題:

String test = "Select * from LeaseNames Where " + col + " ='" + enterLogLN + "'"; 

更改爲:

String test = "Select * from LeaseNames Where " + col[0] + " ='" + enterLogLN + "'"; 

一個更好的查詢:

Cursor cursor = myDataBase.query("LeaseNames", null, "colLeaseNames=?", new String[] { enterLogLN } , null, null, null); 
+0

這樣做,我知道它必須是簡單的 – deerkiller11 2012-07-07 05:11:21

+0

謝謝我會嘗試 – deerkiller11 2012-07-07 05:13:22

0

我們這樣做Android的數據庫插入操作。

 SqliteDataBase SDB = this.getWritableDatabase(); 

    ContentValues values = new ContentValues();// values to insert into DB Table 
    values.put(COLUMNE_NAME1, "data1"); 
    values.put(COLUMND_NAME2, "data2"); 
    values.put(COLUMND_NAME3, "data3"); 
    long id = SDB.insert(TABLE_NAME, null, values); // inserting into table_name will return row id 
    Log.d(TAG, "Event Inserted : " + id); 
    SDB.close(); 

你爲什麼不試試這種方式。