错误:SQLiteLog:(1)没有这样的列:nometprenom

时间:2018-06-02 14:20:56

标签: java xml sqlite android-sqlite

当我尝试执行“SearchPass”时,我在logcat中遇到SQLiteLog: (1) no such column错误。请问我的查询中的错误是什么?

Logcat:

06-02 13:33:17.168 2971-2971/com.example.pc.myapplication E/SQLiteLog: (1) no such column: nometprenom
06-02 13:33:17.169 2971-2971/com.example.pc.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pc.myapplication, PID: 2971
android.database.sqlite.SQLiteException: no such column: nometprenom (code 1): , while compiling: select nometprenom , motdepasse fromcontacts

searchPass方法:

public String searchPass (String nometprenom) {
    db = this.getReadableDatabase();
    String query = "select nometprenom , motdepasse from"+TABlE_NAME;
    Cursor cursor = db.rawQuery(query,null);
    String a,b;
    b= "not found";
    if (cursor.moveToFirst())
    {
        do {
            a = cursor.getString(0);

            if (a.equals(nometprenom)) {
                b = cursor.getString(1);
                break;
            }
        }
        while (cursor.moveToNext());
            }
            return b;
        }

班级contact.java:

public class Contact {
int id  ;
String nometprenom , motdepasse, cin ;
public void setId (int id) {
    this.id=id;
}
public int getId() {
    return this.id ;
}
public void setnometprenom (String nometprenom) {
    this.nometprenom=nometprenom;
}
public String getnometprenom () {
    return this.nometprenom ;
}
public void setcin (String cin) {
    this.cin=cin;
}
public String getcin () {
    return this.cin ;
}
public void setmotdepasse (String motdepasse) {
    this.motdepasse=motdepasse;
}
public String getmotdepasse () {
    return this.motdepasse ;
}

1 个答案:

答案 0 :(得分:0)

注意错误: android.database.sqlite.SQLiteException: no such column: nometprenom (code 1): , while compiling: select nometprenom , motdepasse fromcontacts

在查询中,fromcontacts之间没有空格。构建查询时 - 在from之后添加空格,如下所示:

String query = "select nometprenom , motdepasse from "+TABlE_NAME;