- public class myDatabase {
-
- static final String USERID="_id";
- static final String PASSWORD="password";
- static final String EMAIL="email";
- static final String QQ="qq";
- static final String CAREER="career";
- static final String DB_NAME="myDatabase1";
- static final String DB_TABLE="imfor";
- private static final int VERSION=1;
- private Context mContext;
- SQLiteDatabase mySQLite;
-
- private static String DB_CREATE="CREATE TABLE " +DB_TABLE+" (" +USERID+" INTEGER PRIMARY KEY,"
- +PASSWORD+" TEXT,"
- +EMAIL+" TEXT,"
- +QQ+" TEXT,"
- +CAREER+" TEXT)";
-
-
- private static class MyHelper extends SQLiteOpenHelper{
-
- public MyHelper(Context context) {
- super(context, DB_NAME, null, VERSION);
-
- }
-
- @Override
- public void onCreate(SQLiteDatabase db) {
-
- db.execSQL(DB_CREATE);
- }
-
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
-
-
- }
-
- }
-
-
- public myDatabase(Context context){
- mContext=context;
- }
-
- public void openDatabase(){
- MyHelper myhelper=new MyHelper(mContext);
- //這時創建或打開數據庫,如果數據庫是新創建的則激活SQLiteOpenHelper對象的的onCreate()方法
- mySQLite=myhelper.getWritableDatabase();
- }
-
- public long insert(int id,String password,String email,String qq,String career){
- ContentValues cv=new ContentValues();
- cv.put(USERID, id);
- cv.put(PASSWORD, password);
- cv.put(EMAIL, email);
- cv.put(QQ, qq);
- cv.put(CAREER, career);
- return mySQLite.insert(DB_TABLE, "null",cv);
- }
-
- public Cursor fetchData(int id){
-
- return mySQLite.query(DB_TABLE, new String[] {USERID,PASSWORD,EMAIL,QQ,CAREER}, USERID+"="+id, null, null, null, null);
- }
- }
|