我在用資料庫解決QQ登錄時,出現這個問題
android.database.sqlite.SQLiteException: no such column: number (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM information WHERE number=? and password=?[code=java]
但是我在debug時,資料是可以傳入number和password的
下面是代碼
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myHelper=new MyHelper(this);
Etnumber=findViewById(R.id.et_1);
Etpassword=findViewById(R.id.et_2);
button1=findViewById(R.id.bu_1);
button2=findViewById(R.id.bu_2);
button2.setOnClickListener(this);
button1.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.bu_1:
number=Etnumber.getText().toString().trim();
password=Etpassword.getText().toString();
db=myHelper.getWritableDatabase();
values=new ContentValues();
values.put("number",number);
values.put("password",password);
db.insert("information",null,values);
makeText(this, "資訊已添加", LENGTH_SHORT).show();
db.close();
break;
case R.id.bu_2:
number=Etnumber.getText().toString().trim();
password=Etpassword.getText().toString();
db=myHelper.getReadableDatabase();
Cursor cursor=db.query("information",null,"number=? and password=?",new String[]{number,password},null,null,null);
if(cursor.getCount()==0){
makeText(this, "登錄失敗", LENGTH_SHORT).show();
}else{
makeText(this, "登錄成功", LENGTH_SHORT).show();
cursor.close();
}
db.close();
break;
}
}資料庫代碼
public class MyHelper extends SQLiteOpenHelper {
public MyHelper(@Nullable Context context) {
super(context, "itcast.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE information(_id INTEGER PRIMARY KEY AUTOINCREMENT ,number VARCHAR(20),password VARCHAR(20))");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}uj5u.com熱心網友回復:
看了半天沒看出毛病,是不是其他哪里搞錯了uj5u.com熱心網友回復:
同問,我找半天沒bug轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/43951.html
標籤:Android
上一篇:如何在ios下的python環境中引入numpy和cv2模塊
下一篇:ios做不規則圖片的鏤空(中空)
