i'm using sqlite in my app and i created another app with configurations for my first app, only to update the sqlite options for my main app. But i can't access the same sqlite database.
If i use the configuration app and execute a update query, my database is updated but only in configuration app. For example the IP, i need to update the IP of my main app in the configuration.
I'm using this same class in my two apps.
public class BDCore extends SQLiteOpenHelper {
private static final String DB_NAME = "NewPointerBI";
private static final int DB_VERSION = 3;
public BDCore(Context ctx){
super(ctx, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("create table user(code integer primary key, ip text not null");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("drop table user;");
onCreate(db);
}
}
and access with this same class:
public class DBLiteConnection {
private SQLiteDatabase db;
public DBLiteConnection(Context ctx){
DBCore dbcore = new DBCore(ctx);
db = dbcore.getWritableDatabase();
}
public DBLiteUser search() {
DBLiteUser user = new DBLiteUser();
String[] columns = new String[]{"code", "ip"};
Cursor cursor = db.query("user", columns, null, null, null, null, null);
if (cursor.getCount() > 0) {
cursor.moveToFirst();
user.setCode(cursor.getInt(0));
user.setIp(cursor.getString(1));
}
return user;
}
public void updateconfig(int code, String ip){
ContentValues values = new ContentValues();
values.put("ip",ip);
db.update("user", values, "code = "+code, null);
}
public void insertdata(int code){
ContentValues values = new ContentValues();
values.put("code",1);
values.put("ip","xxx.xxx.xxx");
db.insert("user", null, values);
}
}
Aucun commentaire:
Enregistrer un commentaire