app fc查询sqlite数据库

时间:2012-07-07 04:38:42

标签: android sqlite

对不起这个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或query语句查询数据库时,应用程序崩溃,日志指向我的查询语句。我想在表“LeaseNames”中查找“colLeaseNames”列中与变量字符串“enterLogLN”(来自editText)匹配的字符串,然后从同一行的“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 个答案:

答案 0 :(得分: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();

你为什么不试试这种方式。

答案 1 :(得分: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);