为什么只获取用户名?

时间:2019-03-10 18:06:01

标签: android database

我想返回用户名和密码,但只返回用户名。这是我的java代码。请检查它,并帮助我找出错误。

String query = "Select * FROM " + Table_name_student
                + " WHERE " + col1 + " =  \""
                + usrname +"\""+"and "+col4+" =  \""+password;
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(query, null);
        if(cursor.getCount() <= 0) {
            cursor.close();
            db.close();
            return false;
        }
        else
        {
            cursor.close();
            db.close();
            return true;
        }

我的xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".aboutus">

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="17dp"
        android:layout_marginLeft="17dp"
        android:layout_marginTop="110dp"
        android:text="Work colleagues and friends noted that
         Lincoln had a capacity to defuse tense and argumentative situations,
         though the use of humour and his capacity to take an optimistic view of human nature.
        He loved to tell stories to illustrate a serious point through the use of humour and parables" />
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

您没有在输入密码后关闭“ \”:

String query = "Select * FROM " + Table_name_student
                + " WHERE " + col1 + " =  \""
                + usrname +"\""+"and "+col4+" =  \""+password + "\"";\\<--- here
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(query, null);
        if(cursor.getCount() <= 0) {
            cursor.close();
            db.close();
            return false;
        }
        else
        {
            cursor.close();
            db.close();
            return true;
        }