I'm novice in Android and I trying to create BD sqlite with API. My class exted SQLiteHelper, the constructor method is OK but the create method not is call. No error in compilation.
MainActivity.java code:
public class MainActivity extends ActionBarActivity {
private DBTesteHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dbHelper = new DBTesteHelper(this);
setContentView(R.layout.activity_main);
}
}
DBTesteHelper.java code:
public class DBTesteHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "bd_teste.db";
private static final int DATABASE_VERSION = 1;
public DBTesteHelper(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_TABLE_STUDENT = "CREATE TABLE tb_estudante ("
+ " id INTEGER PRIMARY KEY AUTOINCREMENT ,"
+ " name TEXT, "
+ " idade INTEGER, "
+ " email TEXT )";
db.execSQL(CREATE_TABLE_STUDENT);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS tb_estudante");
onCreate(db);
}
}
Aucun commentaire:
Enregistrer un commentaire