与rawQuery有什么不对,为什么从编辑文本中获取字符串以检查db总是崩溃...错误没有这样的列:aaaa ...在编译时:SELECT * FROM ....
public boolean isGotName(String Pname){
boolean result = false;
Cursor sName = ourDatabase.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + Pro_Name + "=" + Pname, null);
result = true;
int numberOfRows = sName.getCount();
if(numberOfRows <= 0)
{
result = false;
return result;
}
result = true;
return result;
}//isGOtId
在这里
Database dbc = new Database(this);
dbc.open();
String Pname = searchId.getText().toString();
boolean checkName = dbc.isGotName(Pname);
// boolean checkName = true;
if(checkName == true){
String s = searchId.getText().toString();
Bundle b = new Bundle();
b.putString("key",s);
b.putInt("keyX", radioBtnFlag);
Intent a = new Intent(SearchUpdate.this, UpdateDelete.class);
a.putExtras(b);
startActivity(a);
searchId.setText(null);
}else{
Dialog d = new Dialog(this);
d.setTitle("Error!");
TextView tv = new TextView(this);
tv.setText("This Search is allow only ID!" + radioBtnFlag );
d.setContentView(tv);
d.show();
searchId.setText(null);
}
...
db.execSQL(" CREATE TABLE " + TABLE_NAME + " ( "
+ Pro_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ Pro_Name + " TEXT NOT NULL, "
+ Pro_Price + " Integer Not null, "
+ Pro_Description + " TEXT NOT NULL, "
+ Pro_Date + " TEXT NOT NULL ); " );
答案 0 :(得分:0)
Cursor sName = ourDatabase.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + Pro_Name + "= '"+ Pname +"'", null);