0
public class MyDataBaseHelper extends SQLiteOpenHelper{
public static final String CREATE_BOOK = "creat table book ("
+ "id integer primary key autoincrement, "
+ "author text, "
+ "price real, "
+ "pages integer, "
+ "name text)";
private Context mContext;
public MyDataBaseHelper(Context context,String name,CursorFactory factory,int version)
{
super(context ,name, factory, version);
mContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_BOOK);
Toast.makeText(mContext,"Creat succeeded",Toast.LENGTH_SHORT).show();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
public class MainActivity extends Activity {
private MyDataBaseHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dbHelper = new MyDataBaseHelper(this,"BookStore.db",null,1);
Button createDatabase = (Button) findViewById(R.id.create_database);
createDatabase.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dbHelper.getWritableDatabase();
}
});
}
}
樣本只是有一個按鈕「創建數據庫」。但是當我點擊按鈕,它brokedown.I不知道什麼是錯的,我從來沒有學過SQL,以上這些代碼都是來自book。我想念什麼?或者我的代碼有什麼問題?謝謝。關於創造一個簡單的SQLite數據庫
是什麼錯誤消息說查詢?檢查你的logcat。 –