1

Player1というアプリで作成されたfirst.dbというデータベースがあります。同じデータベースを使用して、Player2 という別のアプリから別のテーブルを作成したいと考えています。Player1 から player2 にも同じ「sharedUserId」を提供しています。しかし、アプリ「Player2」でテーブルを作成しようとすると、テーブルのonCreateメソッドに行きません。

    public static final String KEY_ID="_id";
public static final String KEY_ClIENTID="_clientid";
public static final String KEY_LOCATION="_location";
public static final String KEY_MASTERDIRECTOR="_masterdirector";
public static final String KEY_IPADDRESS="_ipaddress";
public static final String KEY_SUBNETMASK="_subnetmask";
public static final String DATABASE_TABLE ="preptool";

private static final String DB_NAME = "first.db";
private static final int DB_VERSION = 1;

private DbHelper ourhelper;
private Context context;
private SQLiteDatabase ourdatabase; 

public dataBase(Context sharedContext){
    context = sharedContext; 
}
public class DbHelper extends SQLiteOpenHelper{

    public DbHelper(Context c) {
        super(c, DB_NAME, null, DB_VERSION); 
    }
    @Override
    public void onCreate(SQLiteDatabase db) { 
        System.out.println("in");
        try{
        db.execSQL("CREATE TABLE " + DATABASE_TABLE + " ("  +
                KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_ClIENTID + " TEXT NOT NULL, " +
                KEY_LOCATION + " TEXT NOT NULL, " +
                KEY_MASTERDIRECTOR + " TEXT NOT NULL, " +
                KEY_IPADDRESS + " TEXT NOT NULL, " +                    
                KEY_SUBNETMASK + " TEXT NOT NULL);");  
        }catch(Exception e){
        }
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE ); 
        onCreate(db);
    }
}
public dataBase open()throws SQLException{
    ourhelper = new DbHelper(context);  System.out.println(context);
    ourdatabase = ourhelper.getWritableDatabase(); 
    return this;
}
public void close(){
    ourhelper.close();
}

以下のコードは、Player1 アプリからデータベースにアクセスするために Player2 アプリケーションで記述しています。

     Context sharedContext = null;
    try {
          sharedContext =     this.createPackageContext("com.xxx.android.player1",Context.CONTEXT_INCLUDE_CODE);
          if (sharedContext == null) {
                return;
          }
    } catch (NameNotFoundException e1) {
    }

    db = new dataBase(sharedContext);
    db.open(); 
4

0 に答える 0