当我执行搜索方法时,它给了我运行时错误
error:- 05-04 14:04:00.227: E/AndroidRuntime(4559): Caused by:
android.database.sqlite.SQLiteException: no such column: ww (code 1): ,
while compiling: SELECT DISTINCT faculty, deparment, name, officeNumber,
phoneNumber, emailAddress, officeHour FROM teacherInfo WHERE name=ww
当用户输入姓名时,我需要搜索教师姓名并显示有关该教师的所有信息,例如姓名,教师,部门,电话,电子邮件,办公号码,办公时间
这是 DBAdapter.java 中的 getRecord 方法
public Cursor getRecord(String n1) throws SQLException
{
Cursor mCursor =db.query(true,tableName , new String[] {facultyc,
deparmentc, namec, officeNumberc,Phonec ,emailAddressc,officeHourc},namec + "=" + n1, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
以及 Information.java 中的这种搜索方法
public void search(){
db.open();
Cursor c = db.getRecord(n);
if (c.moveToFirst()){
t1.setText(c.getString(0));
t2.setText(c.getString(1));
t3.setText(c.getString(2));
t4.setText(c.getString(3));
t5.setText(c.getString(4));
t6.setText(c.getString(5));
t7.setText(c.getString(6));
}
else
Toast.makeText(this, "this Dr not found", Toast.LENGTH_LONG).show();
db.close();
}
DBAdapter.java 中的这个 Oncreate 方法
public void onCreate(SQLiteDatabase db)
DATABASE_CREATE =
"create table if not exists teacherInfo (teacherNumber INTEGER primary key autoincrement,"
+ "name TEXT not null, faculty TEXT,deparment TEXT,officeNumber INTEGER,officeHour TEXT, emailAddress TEXT,phoneNumber TEXT, location INTEGER );";
{
try {
db.execSQL(DATABASE_CREATE);
} catch (SQLException e) {
e.printStackTrace();
}
}