i am try to insert user and pass to login table it shows an error, i am passing username,password as construtor to database class. now i want to insert username and password to login page
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();
}
}
You haven’t created your database… the onCreate method is empty, nor do I see you use your table creation string anywhere else.
Your onUpgrade needs a little help too (it’ll delete the table but not re-create it):
Hope this helps!