此代码没有创建我的数据库。我想在创建表时创建一个带有一些默认值的预填充表。虽然执行时没有错误。有什么帮助吗?
数据库助手代码:
public class DatabaseHelper extends SQLiteOpenHelper {
public static String dbName = "whatever.db";
public static int dbVersion = 2;
public DatabaseHelper(Context context) {
super(context, dbName, null, dbVersion);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String createTable = "CREATE TABLE smart (UID INTEGER PRIMARY KEY, NAME TEXT);";
db.execSQL(createTable);
ContentValues cv = new ContentValues();
cv.put("UID", 9);
cv.put("NAME", "clear");
db.insert("smart", null, cv);
db.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS smart");
}
}
主要活动代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DatabaseHelper dbHelper = new DatabaseHelper(this);
dbHelper.close();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}