我正在创建一个登录页面。
问题是我的SQLite数据库不允许我移动到下一页 我创建了两个类
现在,当我想进一步移动时,数据库助手会出错 在这方面的任何帮助将受到高度赞赏。
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper{
private static final int DATABASE_VERSIO=1;
private static final String DATABASE_NAME="contacts.db";
private static final String TABLE_NAME="contacts";
private static final String COLUMN_ID="id";
private static final String COLUMN_NAME="name";
private static final String COLUMN_EMAIL="email";
private static final String COLUMN_UNAME="uname";
private static final String COLUMN_PASS="pass";
SQLiteDatabase db;
private static final String TABLE_CREATE="create table contacts(id integer primary key not null auto_increment,"+
"name text not null,email text not null,uname text not null,pass text not null);";
public DatabaseHelper(Context context){
super(context,DATABASE_NAME,null,DATABASE_VERSIO );
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
db.execSQL(TABLE_CREATE);
this.db=db;
}
public void insertContact(Contact c){
db=this.getWritableDatabase();
ContentValues values=new ContentValues();
String query="select * from contacts";
Cursor cursor=db.rawQuery(query,null);
int count=cursor.getCount();
values.put(COLUMN_ID,count);
values.put(COLUMN_NAME,c.getName());
values.put(COLUMN_EMAIL,c.getEmail());
values.put(COLUMN_UNAME,c.getName());
values.put(COLUMN_PASS,c.getPass());
db.insert(TABLE_NAME,null,values);
db.close();
}
public String searchPass(String uname){
db=this.getReadableDatabase();
String query="select uname,pass from"+TABLE_NAME;
Cursor cursor=db.rawQuery(query,null);
String a,b;
b="not found";
if (cursor.moveToFirst())
{
do {
a=cursor.getString(0);
if (a.equals(uname))
{
b=cursor.getString(1);
break;
}
}while (cursor.moveToNext());
}
return b;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String query="DROP TABLE EXISTS"+TABLE_NAME;
db.execSQL(query);
this.onCreate(db);
}
}