我似乎无法做到这一点,所以我问我在代码中忽略了什么。这是我的代码中的内容:
newLeaseData = "INSERT INTO " + enterLogLN + " (Date, "
+ "StockTank1Ft, StockTank1Inch, StockTank2Ft, StockTank2Inch, "
+ "StockTank3Ft, StockTank3Inch, StockTank4Ft, StockTank4Inch, "
+ "Change1, Change2, Change3, Change4) VALUES "
+ "(" + today + ", '" + valueT1Ft + "', '" + valueT1Inch + "', '" + valueT2Ft
+ "', '" + valueT2Inch + "', '" + valueT3Ft + "', '" + valueT3Inch
+ "', '" + valueT4Ft + "', '" + valueT4Inch + "', " + difTotalT1
+ ", " + difTotalT2 + ", " + difTotalT3 + ", " + difTotalT4 + ")";
一切正常,直到我得到字符串:difTotalT1、difTotalT2、difTotalT3 和 difTotalT4。每个字符串都设置为: 0'-1" 、 0'-2" 、 0'-3" 或 0'-4" ,当我尝试执行命令时:
myDataBase.execSQL(EnterLogDataOilActivity.newLeaseData);
我的应用程序因此 logcat 错误而崩溃:
06-05 04:36:23.824: E/AndroidRuntime(1127): android.database.sqlite.SQLiteException: "'-1", 0'" 附近: 语法错误: INSERT INTO about (Date, StockTank1Ft, StockTank1Inch, StockTank2Ft, StockTank2Inch,StockTank3Ft,StockTank3Inch,StockTank4Ft,StockTank4Inch,Change1,Change2,Change3,Change4)值('05_05_12','0','1','0','2','0','3','0' ', '4', 0'-1", 0'-2", 0'-3", 0'-4")
感谢您的帮助,我知道它必须很简单。我也尝试用单引号括住每个 difTotalT1 字符串,但这也不起作用(即 difTotalT1 = "'" + difTotalT1 + "'";)
这是我用来在 sqlite 中创建表的字符串:
newLeaseTable = "create table '" + leaseName + "' (_id integer primary key autoincrement,"
+ " Date TEXT, StockTank1Ft NUMERIC, StockTank1Inch NUMERIC,"
+ " StockTank2Ft NUMERIC, StockTank2Inch NUMERIC, StockTank3Ft NUMERIC,"
+ " StockTank3Inch NUMERIC, StockTank4Ft NUMERIC, StockTank4Inch NUMERIC,"
+ " Change1 TEXT, Change2 TEXT, Change3 TEXT, Change4 TEXT, User TEXT);";