0

对不起,noop 问题,但我只是无法缝合让它工作。我用这个命令创建了我的数据库表:

    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'
4

2 回答 2

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();

你为什么不试试这个方法。

于 2012-07-07T04:55:55.927 回答
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);
于 2012-07-07T05:04:41.417 回答