对这方面的掌握不牢,慢慢深入吧,先执行一个sqlite语句,只会简单的.输出"创建"证明创建成功
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Mysqlite mysqlite = new Mysqlite(this, "student", null, 2);
}
}
上面是主activity
public class Mysqlite extends SQLiteOpenHelper {
SQLiteDatabase readableDatabase;
public Mysqlite(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
readableDatabase = getWritableDatabase();//创建数据库不需要什么权限,但是这行代码一定要写
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table student (id integer,name varchar)");
System.out.println("创建");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
继承DBhelp并实现两个方法
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!