我想使用创建数据库的 SQLLIte 创建简单的登录系统,但光标中出现错误。
我的数据库代码是
public static final String KEY_RAWID = "_id";
public static final String KEY_RAWNAME = "name";
public static final String KEY_PASSWORD = "password";
public static final String KEY_EMAIL = "email";
private static final String DATABASE_NAME = "users_DB";
private static final String DATABASE_TABLE = "users";
private dbusers ourhelper;
private final Context ourcontext;
private SQLiteDatabase ourDatabase;
private static class dbusers extends SQLiteOpenHelper {
public dbusers(Context context) {
super(context, DATABASE_TABLE, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE + "(" + KEY_RAWID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_RAWNAME
+ " TEXT NOT NULL, " + KEY_PASSWORD + " TEXT NOT NULL, "
+ KEY_EMAIL + " TEXT NOT NULL);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE);
onCreate(db);
}
}
public Dbinfo(Context c) {
ourcontext = c;
}
public Dbinfo open() {
ourhelper = new dbusers(ourcontext);
ourDatabase = ourhelper.getWritableDatabase();
return this;
}
public void close() {
ourhelper.close();
}
我在这个函数中有错误
public Boolean check(String nameS, String passwordS) {
// TODO Auto-generated method stub
String[] columns = new String[] { KEY_RAWID, KEY_RAWNAME, KEY_PASSWORD,
KEY_EMAIL };
Cursor c = null;
Boolean check = true;
c=ourDatabase.rawQuery("SELECT name,password FROM users WHERE name="+nameS,null);
if (c.getCount() > 0)// && c2.getCount() > 0) {
{ check = false;
return check;
}
return check;
错误:
04-15 00:29:23.302: E/AndroidRuntime(1300): android.database.sqlite.SQLiteException: no such column: khaled: , while compiling: SELECT name,password FROM users WHERE name=khaled
虽然我已经在数据库中添加了数据,并且我检查了数据库中的数据是否添加成功。有什么帮助吗?