public class MyDatabaseHelper extends SQLiteOpenHelper
{
final String CREATE_TABLE_SQL =
"create table dict(_id integer primary " +
"key autoincrement , word , detail)";
public MyDatabaseHelper(Context context, String name, int version)
{
super(context, name, null, version);
}
@Override
public void onCreate(SQLiteDatabase db)
{
// 第一次使用數據庫時自動建表
db.execSQL(CREATE_TABLE_SQL);
}
@Override
public void onUpgrade(SQLiteDatabase db
, int oldVersion, int newVersion)
{
System.out.println("--------onUpdate Called--------"
+ oldVersion + "--->" + newVersion);
}
}
public class Dict extends Activity{
MyDatabaseHelper dbHelper;
Button insert = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dbHelper = new MyDatabaseHelper(this , "myDict.db3",1);
insert = (Button) findViewById(R.id.insert);
insert.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
String word = ((EditText)findViewById(R.id.word)).getText().toString();
String detail = ((EditText)findViewById(R.id.detail)).getText().toString();
insertData(dbHelper.getReadableDatabase(),"56465" ,"56165");
}
});
}
private void insertData(SQLiteDatabase db , String word , String detail){
db.execSQL("insert into dict values(null,?,?)" , new String[] {word ,detail});
}
}
insertData(dbHelper.getWritableDatabase(),"56465" ,"56165");不是getReadableDatabase