我无法理解为什么数据库要么不保存我输入的值,要么是我用来拉动所有数据无法正常工作的方法。它不会抛出任何它无法正常工作的错误。这是代码:
private static final String QUERY_TRIANGLE_CREATE_TABLE =
"CREATE TABLE " + TRIANGLE_TABLE_NAME + " (" + TRIANGLE_COL_ID + " INTEGER PRIMARY KEY, " +
TRIANGLE_VALUE_A + " TEXT, " + TRIANGLE_VALUE_C + "TEXT, " + TRIANGLE_VALUE_B + " TEXT, " + TRIANGLE_RESULT + " TEXT," + TRIANGLE_HISTORY_INFORMATION + " TEXT" + " );";
public void insertTriangleCalc(String a,String b, String c,String d,String e){
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(TRIANGLE_VALUE_A,a);
values.put(TRIANGLE_VALUE_B,b);
values.put(TRIANGLE_VALUE_C,c);
values.put(TRIANGLE_RESULT,d);
values.put(TRIANGLE_HISTORY_INFORMATION,e);
database.insert("triangle", null, values);
database.close();
}
public void insertTriangleCalc(String a,String b, String c,String d){
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(TRIANGLE_VALUE_A,a);
values.put(TRIANGLE_VALUE_B,b);
values.put(TRIANGLE_RESULT,c);
values.put(TRIANGLE_HISTORY_INFORMATION,d);
database.insert("triangle", null, values);
database.close();}
public List<Triangle> ObjectRead() {
List<Triangle> valuesList = new ArrayList<>();
String sql = "SELECT * FROM triangle ORDER BY id DESC";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(sql, null);
if (cursor.moveToFirst()) {
do {
int id = Integer.parseInt(cursor.getString(cursor.getColumnIndex("id")));
String valueA = cursor.getString(cursor.getColumnIndex("valueA"));
String valueB = cursor.getString(cursor.getColumnIndex("valueB"));
String valueC="0";
try {
} catch (Exception e){
}
String result = cursor.getString(cursor.getColumnIndex("result"));
String history = cursor.getString(cursor.getColumnIndex("history"));
Triangle triangle = new Triangle();
triangle.id = id;
triangle.valueA = valueA;
triangle.valueB = valueB;
triangle.valueC = valueC;
triangle.Result = result;
triangle.history = history;
valuesList.add(triangle);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return valuesList;
}
任何人都可以查看它并帮我弄清楚我没有正确设置的内容。它适用于public void insertTriangleCalc(String a,String b,String c,String d),但不适用于public void insertTriangleCalc(String a,String b,String c,String d,String e)。
答案 0 :(得分:0)
决定从上到下进行检查,由于缺少空白空间而发生了整件事情:TRIANGLE_VALUE_C +&#34; TEXT,&#34; &lt; - 这里。现在已经解决了,它最终可以正确存储数据。