我不久前发布了一个解决我遇到的语法错误的解决方案,并且有人设法帮助我,但它并没有完全解决我的问题,因为我的语法在创建我的表时仍然是错误的。我的应用程序运行时很奇怪,但我仍然收到编译错误。
以下是我收到的错误:
android.database.sqlite.SQLiteException:near“?”:语法错误(代码1):,同时编译:create table Business_Trip_Expenditure(desc text primary key,Meals integer NOT NULL,Drinks integer NOT NULL,Travel integer NOT NULL ,Accommodation整数NOT NULL,其他整数NOT NULL,Receipt_Retained?real NOT NULL,Created_at text NOT NULL);
这是我的代码:
public class MySQLiteHelper extends SQLiteOpenHelper {
public static final String TABLE_NAME = "Business_Trip_Expenditure";
//Column Names
public static final String COLUMN_NAME = "desc";
public static final String MEAL_COST ="Meals";
public static final String DRINK_COST = "Drinks";
public static final String TRAVEL_COST = "Travel";
public static final String ACCO_COST = "Accommodation";
public static final String OTHER_COST = "Other";
public static final String HAS_RECEIPT = "Receipt_Retained";
public static final String CREATED_AT = "Created_at";
private static final String DATABASE_NAME = "trip.db";
private static final int DATABASE_VERSION = 1;
// Database creation sql statement
private static final String DATABASE_CREATE = "create table "
+ TABLE_NAME + "( " + COLUMN_NAME + " text primary key ," + MEAL_COST + " integer NOT NULL ," + DRINK_COST + " integer NOT NULL ," + TRAVEL_COST + " integer NOT NULL ," + ACCO_COST + " integer NOT NULL ," + OTHER_COST + " integer NOT NULL ," + HAS_RECEIPT + " real NOT NULL ," + CREATED_AT + " text NOT NULL);";
public MySQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(MySQLiteHelper.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
再说一遍,如果有人能帮我解决这个问题,那对我来说将是一个很大的帮助,非常感谢。对于垃圾邮件问题也很抱歉。
答案 0 :(得分:0)
看看你的代码,这是一团糟。难怪你找不到任何错误。感受差异
<string name="createTableOfPrimes">CREATE TABLE prime ( _id INTEGER PRIMARY KEY AUTOINCREMENT, prime_no TEXT, date_time DATETIME DEFAULT CURRENT_TIMESTAMP );</string>
答案 1 :(得分:0)
很难调试这样的查询。尝试使用一些字符串构建器工具来格式化您的查询。 Selectionbuilder或square短语是一些很好的选择:
答案 2 :(得分:0)
尝试创建新的数据库表(更改数据库表名称),然后重试。这是我建议你查看代码的唯一方法。