我有这样的源代码:
if (proses == 3) {
HistoryConnector dbkonek = new HistoryConnector(this);
dbkonek.open();
//CURSOR air
cursorSumberAir = dbkonek.getOneDataSumberAir(rowId);
cursorKegunaanAir = dbkonek.getOneDataKegunaanAir(rowId);
cursorSifatAir = dbkonek.getOneDataSifatAir(rowId);
cursorPerlakuanAir = dbkonek.getOneDataPerlakuanAir(rowId);
cursorPenyimpananAir = dbkonek.getOneDataPenyimpananAir(rowId);
cursorSanitasi = dbkonek.getOneDataSanitasi(rowId);
cursorSumberAir.moveToFirst();
cursorKegunaanAir.moveToFirst();
cursorSifatAir.moveToFirst();
cursorPerlakuanAir.moveToFirst();
cursorPenyimpananAir.moveToFirst();
cursorSanitasi.moveToFirst();
} else {
DatabaseConnector dbkonek = new DatabaseConnector(this);
dbkonek.open();
//CURSOR air
cursorSumberAir = dbkonek.getOneDataSumberAir(rowId);
cursorKegunaanAir = dbkonek.getOneDataKegunaanAir(rowId);
cursorSifatAir = dbkonek.getOneDataSifatAir(rowId);
cursorPerlakuanAir = dbkonek.getOneDataPerlakuanAir(rowId);
cursorPenyimpananAir = dbkonek.getOneDataPenyimpananAir(rowId);
cursorSanitasi = dbkonek.getOneDataSanitasi(rowId);
cursorSumberAir.moveToFirst();
cursorKegunaanAir.moveToFirst();
cursorSifatAir.moveToFirst();
cursorPerlakuanAir.moveToFirst();
cursorPenyimpananAir.moveToFirst();
cursorSanitasi.moveToFirst();
}
我想要这个:如果proses == 3
然后dbkonek
创建新的HistoryConnector
. 否则dbkonek
创建新DatabaseConnector
的,我怎么能做到这一点?因为当我制作这样的来源时:
if (proses == 3) {
HistoryConnector dbkonek = new HistoryConnector(this);
dbkonek.open();
} else {
DatabaseConnector dbkonek = new DatabaseConnector(this);
dbkonek.open();
}
//CURSOR air
cursorSumberAir = dbkonek.getOneDataSumberAir(rowId);
cursorKegunaanAir = dbkonek.getOneDataKegunaanAir(rowId);
cursorSifatAir = dbkonek.getOneDataSifatAir(rowId);
cursorPerlakuanAir = dbkonek.getOneDataPerlakuanAir(rowId);
cursorPenyimpananAir = dbkonek.getOneDataPenyimpananAir(rowId);
cursorSanitasi = dbkonek.getOneDataSanitasi(rowId);
cursorSumberAir.moveToFirst();
cursorKegunaanAir.moveToFirst();
cursorSifatAir.moveToFirst();
cursorPerlakuanAir.moveToFirst();
cursorPenyimpananAir.moveToFirst();
cursorSanitasi.moveToFirst();
编辑,任何一个这样的连接器:
public class DatabaseConnector {
private static final String DB_NAME = "DataAssessment.db";
private SQLiteDatabase database;
private DatabaseOpenHelper dbOpenHelper;
public DatabaseConnector(Context context) {
dbOpenHelper = new DatabaseOpenHelper(context, DB_NAME, null, 1);
}
}
上面的源代码,dbkonek
无法在游标中检测到。我怎么能简单这个源代码。感谢提前