有没有办法同时从数据库中获取String和Boolean Value?

时间:2015-01-27 10:18:34

标签: android android-cursor

我们可以同时从数据库中获取布尔值和字符串值吗?

请在下面查询我想要做同样的事情: -

    if(uname.equals("") || uname == null){
            Toast.makeText(getApplicationContext(), "Username Empty", Toast.LENGTH_SHORT).show();
        }else if(pass.equals("") || pass == null){
            Toast.makeText(getApplicationContext(), "Password Empty", Toast.LENGTH_SHORT).show();
        }else{
            Database ValidLogin = new Database(User.this);
            ValidLogin.open();

            boolean validLogin = ValidLogin.validate(uname, pass);


            ValidLogin.close();

另外,找到以下数据库助手类: -

     public boolean validate(String uname, String pass) {
    // TODO Auto-generated method stub

    // SELECT
    String[] columns = { "_id" };

    // WHERE clause
    String selection = "user_name = ? AND _password = ?";

    // WHERE clause arguments
    String[] selectionArgs = { uname, pass };

    Cursor cursor = ourDatabase.query(DATABASE_TABLE, columns, selection,
            selectionArgs, null, null, null);
    try {
        if (cursor != null && cursor.getCount() > 0) {
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();

    }

    cursor.close();
    return false;

请建议任何链接或解决方法吗?

提前谢谢你:)

0 个答案:

没有答案