在我的应用程序中,我使用的是 SQLite 数据库。在我的一个表中插入数据时,我遇到了“SQLite 异常:错误 19”的奇怪问题。第一次插入数据,但是当我再次尝试插入数据时,它会抛出异常。
我的创建表查询:
"CREATE TABLE Tickets ("
+ "ID integer PRIMARY KEY NOT NULL,"
+ " UID varchar(40) NOT NULL DEFAULT 'not available'," + " OrderID int NOT NULL,"
+ " CarrierTicketNum varchar(15) NOT NULL,"
+ " TicketTypeID int NOT NULL," + " TankTypeID int NULL,"
+ " ProductObsGravity numeric NULL DEFAULT 0,"
+ " ProductHighTemp numeric NULL DEFAULT 0,"
+ " ProductLowTemp numeric NULL DEFAULT 0,"
+ " ProductObsTemp numeric NULL DEFAULT 0,"
+ " ProductBSW numeric NULL DEFAULT 0");
插入查询:
public void insertTank(int OrderID, int TicketTypeID,
String CarrierTicketNum, String TankNum, int TankTypeID,
Double ProductObsTemp, Double ProductObsGravity, Double ProductBSW,
Double GrossBarrels, Double NetBarrels) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("OrderID", OrderID);
values.put("CarrierTicketNum", CarrierTicketNum);
values.put("TankNum", TankNum);
values.put("TicketTypeID", TicketTypeID);
values.put("TankTypeID", TankTypeID);
values.put("ProductObsTemp", ProductObsTemp);
values.put("ProductObsGravity", ProductObsGravity);
values.put("ProductBSW", ProductBSW);
values.put("GrossBarrels", GrossBarrels);
values.put("NetBarrels", NetBarrels);
//try {
db.insertOrThrow("Tickets", null, values);
/*} catch (SQLiteException sqle) {
Log.d(TAG, "SQLITException: " + sqle.getMessage());
}*/
db.close(); // Closing database connection
}
以下是日志详细信息:
09-08 13:54:57.610: E/AndroidRuntime(5713): FATAL EXCEPTION: main
09-08 13:54:57.610: E/AndroidRuntime(5713): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
09-08 13:54:57.610: E/AndroidRuntime(5713): at android.database.sqlite.SQLiteStatement.native_executeInsert(Native Method)
09-08 13:54:57.610: E/AndroidRuntime(5713): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:113)
09-08 13:54:57.610: E/AndroidRuntime(5713): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1718)
09-08 13:54:57.610: E/AndroidRuntime(5713): at android.database.sqlite.SQLiteDatabase.insertOrThrow(SQLiteDatabase.java:1617)
09-08 13:54:57.610: E/AndroidRuntime(5713): at com.dzo.dispatchcrude.driverapp.datalayer.DatabaseHandler.insertTank(DatabaseHandler.java:736)
09-08 13:54:57.610: E/AndroidRuntime(5713): at com.dzo.dispatchcrude.driverapp.NetBarrelActivity$1.onClick(NetBarrelActivity.java:103)
09-08 13:54:57.610: E/AndroidRuntime(5713): at android.view.View.performClick(View.java:3511)
09-08 13:54:57.610: E/AndroidRuntime(5713): at android.view.View$PerformClick.run(View.java:14110)
09-08 13:54:57.610: E/AndroidRuntime(5713): at android.os.Handler.handleCallback(Handler.java:605)
09-08 13:54:57.610: E/AndroidRuntime(5713): at android.os.Handler.dispatchMessage(Handler.java:92)
09-08 13:54:57.610: E/AndroidRuntime(5713): at android.os.Looper.loop(Looper.java:137)
09-08 13:54:57.610: E/AndroidRuntime(5713): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-08 13:54:57.610: E/AndroidRuntime(5713): at java.lang.reflect.Method.invokeNative(Native Method)
09-08 13:54:57.610: E/AndroidRuntime(5713): at java.lang.reflect.Method.invoke(Method.java:511)
09-08 13:54:57.610: E/AndroidRuntime(5713): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-08 13:54:57.610: E/AndroidRuntime(5713): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-08 13:54:57.610: E/AndroidRuntime(5713): at
dalvik.system.NativeStart.main(Native Method)
几乎阅读了数字帖子,但没有得到太多帮助。