因为有两个数据库,我有一个问题:
第一个数据库只是读入的一堆值,所以这不是问题。我可以从数据库中提取值,然后使其按预期显示在Android设备上。我遇到的问题是,当我尝试将结果保存到辅助表时,每次运行程序时,它都会重新创建表EVEN(如果存在)。
它正确保存它,当我转到保存的结果屏幕时,单个结果将通过,但如果我返回将另一行保存到此结果表,它将重新创建表并将其添加到第一行。知道如何解决或解决这个问题吗?
我的代码:
MyDataBaseHelper dbCon = new MyDataBaseHelper(this);
dbCon.open();
dbCon.pushToDatabase(uniqueName, date, time, wingType, nozzle, orifice, angle, speed, pressure, dv1, dv5, dv9, sprayVolume1, sprayVolume2, droplet, tableExist);
dbCon.close();
MyDataBaseHelper
public void pushToDatabase(String uniqueName, String date, String time, String wingType, String nozzle, String orifice, String angle, String speed, String pressure,
String dv1, String dv5, String dv9, String sprayVolume1, String sprayVolume2, String droplet, String tableExist)
{
final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS Results("
+ "uniqueName TEXT,"
+ "date TEXT,"
+ "time TEXT,"
+ "wingType TEXT,"
+ "nozzle TEXT,"
+ "orifice TEXT,"
+ "angle TEXT,"
+ "pressure TEXT,"
+ "speed TEXT,"
+ "dv1 TEXT,"
+ "dv5 TEXT,"
+ "dv9 TEXT,"
+ "sprayvolume1 TEXT,"
+ "sprayvolume2 TEXT,"
+ "droplet TEXT);";
myDB.execSQL(CREATE_TABLE);
ContentValues values = new ContentValues();
values.put("uniqueName", uniqueName);
values.put("date", date);
values.put("time", time);
values.put("wingType", wingType);
values.put("nozzle", nozzle);
values.put("orifice", orifice);
values.put("angle", angle);
values.put("pressure", pressure);
values.put("speed", speed);
values.put("dv1", dv1);
values.put("dv5", dv5);
values.put("dv9", dv9);
values.put("sprayvolume1", sprayVolume1);
values.put("sprayvolume2", sprayVolume2);
values.put("droplet", droplet);
myDB.insert("Results", null, values);
myDB.close();
//Cursor mCursor;
//mCursor = myDB.rawQuery(data, null);
//mCursor.moveToFirst();*/
}
答案 0 :(得分:2)
我没有编译任何东西,但清楚可见的是,你没有在任何表格字段上设置Primary Key
final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS Results("
+ "uniqueName TEXT,"
+ "date TEXT,"
+ "time TEXT,"
+ "wingType TEXT,"
+ "nozzle TEXT,"
+ "orifice TEXT,"
+ "angle TEXT,"
+ "pressure TEXT,"
+ "speed TEXT,"
+ "dv1 TEXT,"
+ "dv5 TEXT,"
+ "dv9 TEXT,"
+ "sprayvolume1 TEXT,"
+ "sprayvolume2 TEXT,"
+ "droplet TEXT, PRIMARY KEY(uniqueName));";