Database 如何用游标在数据库中搜索长类型

Database 如何用游标在数据库中搜索长类型,database,android-studio,cursor,android-cursor,Database,Android Studio,Cursor,Android Cursor,在向表中添加数据之前,我想确保studentId与另一个studentId不同,但我不知道如何使用游标搜索长类型 我的代码: public void SaveStudent(Long studentId , int classID , String studentName) { String stdId = studentId.toString(); Cursor cursor = database.rawQuery("select * from student wher

在向表中添加数据之前,我想确保studentId与另一个studentId不同,但我不知道如何使用游标搜索长类型

我的代码:

    public void SaveStudent(Long studentId , int classID , String studentName)
{
    String stdId = studentId.toString();
    Cursor cursor = database.rawQuery("select * from student where student_id = ?",
                                        new String[]{stdId});

    if (cursor.getCount() == 0)
    {
        ContentValues values = new ContentValues();

        values.put("student_id", studentId);
        values.put("class_id", classID);
        values.put("student_name", studentName);

        database.insert("student", null, values);

        Toast.makeText(context, "save!", Toast.LENGTH_SHORT).show();
    }
    else
    {
        Toast.makeText(context, "StudentID is duplicate", Toast.LENGTH_SHORT).show();
    }
}
logcat错误:

02-23 21:37:39.108 26986-26986/com.example.user.classmanager E/SQLiteLog: (1) near "=": syntax error
02-23 21:37:39.110 26986-26986/com.example.user.classmanager E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.user.classmanager, PID: 26986
          android.database.sqlite.SQLiteException: near "=": syntax error (code 1): ,           while compiling: select * from studentwhere student_id = ?
          at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
          at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
          at com.example.user.classmanager.DatabaseHandler.SaveStudent(DatabaseHandler.java:184)
          at com.example.user.classmanager.SecondTab$1$1$1.onClick(SecondTab.java:97)
试试下面的方法



    Cursor cursor = database.rawQuery("select * from student where student_id = ?",
                                            new String[]{String.valueOf(stdId)});