android. Database. Sqlite. SQLiteException: no to the column: number (code 1 SQLITE_ERROR) :, while compiling: SELECT * FROM information WHERE number=? And password=? [code=Java]
But when I was in the debug, data can be introduced into number and password
Below is the code
protected void onCreate (Bundle savedInstanceState) {
Super. OnCreate (savedInstanceState);
The setContentView (R.l ayout. Activity_main);
MyHelper=new myHelper (this);
Etnumber=the findViewById (R.i d.e t_1);
Etpassword=the findViewById (R.i d.e t_2);
For the=the findViewById (R.i db u_1);
Button2=the findViewById (R.i db u_2);
Button2. SetOnClickListener (this);
For the setOnClickListener (this);
}
@ Override
Public void onClick (View View) {
The switch (the getId ()) {
Case R.i db u_1:
Number=Etnumber. GetText (). The toString (). The trim ();
Password=Etpassword. GetText (). The toString ();
The db=myHelper. GetWritableDatabase ();
Values=new ContentValues ();
Values. The put (" number ", number).
Values. The put (" password ", ");
The insert (" information ", null values);
MakeText (this, "information have been added," LENGTH_SHORT), show ();
The close ();
break;
Case R.i db u_2:
Number=Etnumber. GetText (). The toString (). The trim ();
Password=Etpassword. GetText (). The toString ();
The db=myHelper. GetReadableDatabase ();
Cursor Cursor=db. The query (" information ", null, "number=? And password=?" , new String [] {number, password}, null, null, null);
If (cursor. GetCount ()==0) {
MakeText (this, "login failed", LENGTH_SHORT), show ();
} else {
MakeText (this, "login succeeds", LENGTH_SHORT), show ();
Cursor. The close ();
}
The close ();
break;
}
}
The database code
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) {
}
}
CodePudding user response:
See half a day did not see, where are the other wrongCodePudding user response:
To ask, I didn't bug for half a day