我尝试插入用户并传递给登录表,它显示错误,我将用户名、密码作为构造函数传递给数据库类。现在我想在登录页面插入用户名和密码
public class Database extends SQLiteOpenHelper{
private static final String DATABASE_NAME = "sample";
private static final int DATABASE_VERSION = 1;
private static final String INSPECTION_CREATE = "CREATE TABLE IF NOT EXISTS login ("
+ "username TEXT," + "password TEXT);";
public Database(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS login");
}
public void insert_datas(String user,String pass,String table_name){
SQLiteDatabase db=this.getWritableDatabase();//in this line error comes
ContentValues initialValues = new ContentValues();
initialValues.put("user",user);
initialValues.put("pass",pass);
long n = db.insert(table_name,user,initialValues);
System.out.println("n"+n);
db.close();
}
}