輸出畫面: 可用cmd 進去 adb shell查詢是否有把資料庫建進去,這範例建的資料庫db1.db
SQLiteExample.java(主程式)
package com.sam.sih;
import android.app.Activity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.os.Bundle;
public class SQLiteExample extends Activity {
MyDatabase dbHelper;
SQLiteDatabase db;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MyDatabase dbHelper = new MyDatabase(this);
db = dbHelper.getWritableDatabase();
}
}
MyDatabase.java (SQLiteOpenHelper擴展來的)
package com.sam.sih;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
class MyDatabase extends SQLiteOpenHelper{
public MyDatabase(Context context) {
super(context, "db1.db", null, 1);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
留言列表