SQLiteOpenHelper显示错误

时间:2016-02-29 09:50:00

标签: android sqlite android-sqlite

我想通过给出一些参数来计算数据库中保存的表的数量。但它显示错误消息

"The method query(boolean, String, String[], String, String[], String,    
 String, String, String, CancellationSignal) in the type SQLiteDatabase is 
 not applicable for the arguments (boolean, String, String[], String, String, 
 String, String[], null, null, null, null)" 

可能是什么原因?

这是我的助手类中的方法:

public int fetchBatches(String jobId, String jobName, String jobType) {

 String columnName = TableClass.COLUMN_JOB_ID, columnValue = jobId,  
 columnJobName = TableClass.COLUMN_JOB_NAME, columnJobValue = jobName, 
            columnJobType =  TableClass.COLUMN_JOB_TYPE, columnJobTypeValue  
  = jobType;

    if (jobId.equalsIgnoreCase("")) {
        columnName = TableClass.COLUMN_JOB_ID;
        columnValue = jobId;
        columnJobName = TableClass.COLUMN_JOB_NAME;
        columnJobValue = jobName;
        columnJobType =  TableClass.COLUMN_JOB_TYPE;
        columnJobTypeValue = jobType;
    }

    Cursor cursor = null;
    SQLiteDatabase database = getReadableDatabase();
    cursor = database.query(true, TableClass.TABLE_PRODUCTS,   //showing 
//error here
            new String[] { TableClass.COLUMN_BATCH }, columnName + " =? and ", columnJobName + " =? and ", columnJobType + "=?",
            new String[] { columnValue,columnJobValue,columnJobTypeValue }, null, null, null, null);


    cursor = database.query(TableClass.TABLE_PRODUCTS,
            null, columnJobType + " =? and " +columnName +" =? ",new String[] 
                    { columnJobTypeValue,columnValue }, null, null, null);

    if (cursor != null) {
        int count = cursor.getCount();
        if (cursor != null) {
            cursor.close();
            database.close();
        }
        return count;
    } else {
        return 0;
    }
}

1 个答案:

答案 0 :(得分:0)

试试这个。希望它有帮助

   cursor = database.query(true, TableClass.TABLE_PRODUCTS,   //showing 
        new String[] { TableClass.COLUMN_BATCH }, columnName + " =? and "+ columnJobName + " =? and " + columnJobType + "=?",
        new String[] { columnValue,columnJobValue,columnJobTypeValue }, null, null, null, null);