无法读取查询

时间:2015-02-14 23:04:54

标签: android mysql sqlite

我想显示特定客户端下的所有项目..但是当我运行它时 - 只显示“No Project!”的toast。我已经将数据存储在数据库中 - 我不知道我的查询有什么问题

就是这样:

btnrefresh.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        String query = "SELECT * FROM " + User.TABLE;
        Cursor cursor = dbHelper.getReadableDatabase().rawQuery(query, null);
        if(cursor.moveToFirst()) {
            if (MainActivity.username.equals(cursor.getString(2))) {
                Toast.makeText(getApplicationContext(), cursor.getString(2), Toast.LENGTH_LONG).show();
                do {
                    if (cursor.getString(3).equals("client")) {
                        comnameproj = cursor.getString(5);
                        Toast.makeText(getApplicationContext(), cursor.getString(5), Toast.LENGTH_LONG).show();
                    }
                }while (cursor.moveToNext());
            }
        }

        String selectQuery = "SELECT * FROM " + Project.TABLE; // + " WHERE " + Project.KEY_companyproj + " = '" + comnameproj + "'";
        Cursor qCursor = dbHelper.getReadableDatabase().rawQuery(selectQuery, null);
        ArrayList<HashMap<String, String>> projectList = new ArrayList<HashMap<String, String>>();

        /* loop through all rows and add to list */
        if (qCursor.moveToFirst()) {
            do { if(qCursor.getString(7).equals(comnameproj)){
                HashMap<String, String> project = new HashMap<String, String>();
                project.put("id", qCursor.getString(Integer.parseInt(String.valueOf(qCursor.getColumnIndex(Project.KEY_ID)))));
                project.put("title", qCursor.getString(qCursor.getColumnIndex(Project.KEY_title)));
                projectList.add(project); }
            } while (qCursor.moveToNext());
        }

        cursor.close();
        qCursor.close();

        ProjectCrud pcrud = new ProjectCrud(ClientModule.this);
        if (projectList.size() != 0) {
            //entrylist = (ListView) findViewById(R.id.list);
            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    project_Id = (TextView) view.findViewById(R.id.project_Id);
                    String projectId = project_Id.getText().toString();
                    Intent objintent = new Intent(getApplicationContext(), ProjectDetail.class);
                    objintent.putExtra("project_Id", Integer.parseInt(projectId));
                    startActivity(objintent);
                }
            });

            ListAdapter adapter = new SimpleAdapter(ClientModule.this, projectList, R.layout.refresh_project, new String[]{"id", "title"}, new int[]{R.id.project_Id, R.id.project_title});
            lv.setAdapter(adapter);
        } else {
            Toast.makeText(ClientModule.this, "No Project!", Toast.LENGTH_LONG).show();
        }

    }

这是我的DBHelper:

  String CREATE_TABLE_PROJECT = "CREATE TABLE " + Project.TABLE + "("
            + Project.KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + Project.KEY_title + " TEXT,"
            + Project.KEY_type + " TEXT,"
            + Project.KEY_timeframe + " TEXT,"
            + Project.KEY_assigned + " TEXT,"
            + Project.KEY_cost + " INTEGER,"
            + Project.KEY_status + " TEXT,"
            + Project.KEY_companyproj + " TEXT,"
            +Project.KEY_month + " TEXT,"
            + Project.KEY_year + " TEXT" + ");";

    db.execSQL(CREATE_TABLE_PROJECT);

    String CREATE_TABLE_USER = "CREATE TABLE " + User.TABLE + "("
            + User.KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + User.KEY_priv +" TEXT,"
            + User.KEY_username + " TEXT,"
            + User.KEY_usertype + " TEXT,"
            + User.KEY_sex + " TEXT,"
            + User.KEY_usercompany + " TEXT,"
            + User.KEY_usermail + " TEXT,"
            + User.KEY_usercontact + " INTEGER,"
            + User.KEY_useradd + " TEXT,"
            + User.KEY_loguser + " TEXT,"
            + User.KEY_logpass + " TEXT,"
            + User.KEY_logconfirm + " TEXT" + ");";

    db.execSQL(CREATE_TABLE_USER);

提前致谢。

0 个答案:

没有答案