在android系统数据库中没有这样的错误列 [英] no such column error in android database
问题描述
当我perfom搜索方法的给我运行时错误
错误: - 05-04 14:04:00.227:E / AndroidRuntime(4559):产生的原因:
android.database.sqlite.SQLiteException:没有这样的列:WW(code 1):
在编译时:SELECT DISTINCT教员,教研室,名称,officeNumber,
phoneNumber的,EMAILADDRESS,officeHour FROM teacherInfo其中name = WW
我要搜索的老师的名字,当用户输入名称和显示有关这位老师,如姓名,院系,教研室,电话,电子邮件,officenumber,officehour
的全部信息thiss getRecord方法DBAdapter.java
公共光标getRecord(字符串N1)抛出的SQLException
{
光标mCursor = db.query(真中,TableName,新的String [] {facultyc,
deparmentc,namec,officeNumberc,Phonec,emailAddressc,officeHourc},namec +=+ N1,NULL,NULL,NULL,NULL,NULL);
如果(mCursor!= NULL){
mCursor.moveToFirst();
}
返回mCursor;
}
和在Information.java这种检索方法
公共无效搜索(){
db.open();
光标C = db.getRecord(N);
如果(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)); } 其他
Toast.makeText(这一点,这个医生没有发现,Toast.LENGTH_LONG).show();
db.close();
}
在此DBAdapter.java onCreate方法
公共无效的onCreate(SQLiteDatabase DB)
DATABASE_CREATE =
创建表,如果不存在teacherInfo(teacherNumber INTEGER主键自动增量
+Name文本不为空,教师TEXT,TEXT教研室,officeNumber INTEGER,officeHour TEXT,TEXT EMAILADDRESS,phoneNumber的TEXT,INTEGER位置);;
{
尝试{
db.execSQL(DATABASE_CREATE);
}赶上(的SQLException E){
e.printStackTrace();
}
}
的问题是,你错过了字符串的报价!
更好地利用字符串参数那样:
公共光标getRecord(字符串N1)抛出的SQLException
{
光标mCursor = db.query(真中,TableName,新的String [] {facultyc,
deparmentc,namec,officeNumberc,Phonec,emailAddressc,officeHourc},
namec +=?,
新的String [] {} WW,NULL,NULL,NULL,NULL);
如果(mCursor!= NULL){
mCursor.moveToFirst();
}
返回mCursor;
}
通过这种方式避免任何错误,也字符串特殊字符转义汽车!
when i perfom search method its given me run time error
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
I need to search on teacher name when user enter the name and display all information about this teacher such as name ,faculty,deparment,phone,email,officenumber,officehour
thiss getRecord method in DBAdapter.java
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;
}
and this search method in 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();
}
this Oncreate method in DBAdapter.java
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();
}
}
The problem is that you missed the quotes of the string!
Better use the String arguments like that:
public Cursor getRecord(String n1) throws SQLException
{
Cursor mCursor =db.query(true,tableName , new String[] {facultyc,
deparmentc,namec,officeNumberc,Phonec,emailAddressc,officeHourc},
namec + "= ? ",
new String[] {ww}, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
By that way you avoid any errors and also string special characters are auto escaped!
这篇关于在android系统数据库中没有这样的错误列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!