我想向我的数据库添加另一个表,但应用程序崩溃并且我收到此错误:
E/SQLiteLog(1025): (1) near "select": syntax error
当我只有一个表时代码正在工作,并且我使用相同的方法创建第二个表,在执行此代码后不久发生崩溃:
db.execSQL(DATABASE_STATS_CREATE);
这是我的课:
BetsDbAdapter.java
public class BetsDbAdapter {
/*-----------------BetList---------------------*/
public static final String KEY_ROWID = "_id";
public static final String KEY_MATCH = "match";
public static final String KEY_TIME = "time";
public static final String KEY_BOOKMAKERS = "bookmakers";
public static final String KEY_ODDS1 = "odds1";
/*-----------------Statistik---------------------*/
public static final String KEY_SID = "_sid";
public static final String KEY_SMATCH = "smatch";
public static final String KEY_SELECTION = "select";
public static final String KEY_BETAMOUNT = "betamount";
public static final String KEY_BODDS = "boods";
private static final String TAG = "BetsDbAdapter";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
private static final String DATABASE_NAME = "Bets.db";
private static final String SQLITE_TABLE = "BetTable";
private static final String SQLITE_STATS_TABLE = "Statistik";
private static final int DATABASE_VERSION = 1;
private final Context mCtx;
private static final String DATABASE_CREATE = "CREATE TABLE if not exists "
+ SQLITE_TABLE + " (" + KEY_ROWID
+ " integer PRIMARY KEY autoincrement," + KEY_MATCH + ","
+ KEY_TIME + "," + KEY_BOOKMAKERS + "," + KEY_ODDS1 + ","
+ " UNIQUE (" + KEY_MATCH + "));";
private static final String DATABASE_STATS_CREATE = "CREATE TABLE if not exists "
+ SQLITE_STATS_TABLE + " (" + KEY_SID
+ " integer PRIMARY KEY autoincrement," + KEY_SMATCH + ","
+ KEY_SELECTION + "," + KEY_BETAMOUNT + "," + KEY_BODDS + ","
+ " UNIQUE (" + KEY_SMATCH + "));";
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.w(TAG, DATABASE_CREATE);
db.execSQL(DATABASE_CREATE);
db.execSQL(DATABASE_STATS_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + SQLITE_TABLE);
db.execSQL("DROP TABLE IF EXISTS " + SQLITE_STATS_TABLE);
onCreate(db);
}
}
public BetsDbAdapter(Context ctx) {
this.mCtx = ctx;
mDbHelper = new DatabaseHelper(mCtx);
}
public BetsDbAdapter open() throws SQLException {
//mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close() {
if (mDbHelper != null) {
mDbHelper.close();
}
}
public long createBets(String match, String time, String bookmakers,
String odds1) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_MATCH, match);
initialValues.put(KEY_TIME, time);
initialValues.put(KEY_BOOKMAKERS, bookmakers);
initialValues.put(KEY_ODDS1, odds1);
return mDb.insert(SQLITE_TABLE, null, initialValues);
}
public long statBets(String smatch, String select, String betamount,
String bodds) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_SMATCH, smatch);
initialValues.put(KEY_SELECTION, select);
initialValues.put(KEY_BETAMOUNT, betamount);
initialValues.put(KEY_BODDS, bodds);
return mDb.insert(SQLITE_STATS_TABLE, null, initialValues);
}