Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am trying to create a table in DB, but I am getting SQLite exception.I have tried almost everything to fix it, but of no use.I dont know why am I getting this error. Removing comma at the end gives another exception : android.database.sqlite.SQLiteException: table products has no column named _cost (code 1):
Any suggestion is welcome.
how do I fix it ?
This is my DB handler class :
public class MyDBHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 4;
private static final String DATABASE_NAME= "products.db";
private static final String TABLE_PRODUCTS = "products";
private static final String COLUMN_ID = "_id";
private static final String COLUMN_PRODUCTNAME = "productname";
private static final String COLUMN_VENUE = "venue";
private static final String COLUMN_DATEOFSTART = "_dateofstart";
private static final String COLUMN_DATEOFEND = "_dateofend";
private static final String DURATION_WORKSHOP= "_duration";
private static final String COST_WORKSHOP = "_cost";
public MyDBHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context,DATABASE_NAME, factory,DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_PRODUCTS + "(" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_PRODUCTNAME + " TEXT, " +
COLUMN_VENUE + " TEXT, " +
COLUMN_DATEOFSTART + " TEXT, " +
COLUMN_DATEOFEND + " TEXT, " +
DURATION_WORKSHOP + "INTEGER, " +
COST_WORKSHOP + "INTEGER, " +
");" ;
db.execSQL(query);
}
#Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_PRODUCTS);
onCreate(db);
}
public void addProduct (Products products){
ContentValues values = new ContentValues();
values.put(COLUMN_PRODUCTNAME,products.get_productname());
values.put(COLUMN_VENUE,products.get_venue());
values.put(COLUMN_DATEOFSTART,products.get_dateofstart());
values.put(COLUMN_DATEOFEND,products.get_dateofend());
values.put(DURATION_WORKSHOP,products.get_duration());
values.put(COST_WORKSHOP,products.get_cost());
SQLiteDatabase db = getWritableDatabase();
db.insert(TABLE_PRODUCTS,null,values);
db.close();
}
LOGCAT :
Caused by: android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: CREATE TABLE products(_id INTEGER PRIMARY KEY AUTOINCREMENT, productname TEXT, venue TEXT, _dateofstart TEXT, _dateofend TEXT, _durationINTEGER, _costINTEGER, );
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1675)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1606)
at com.example.dell_1.sqlite.MyDBHandler.onCreate(MyDBHandler.java:38)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at com.example.dell_1.sqlite.MyDBHandler.addProduct(MyDBHandler.java:57)
at com.example.dell_1.sqlite.MainActivity.onCreate(MainActivity.java:24)
at android.app.Activity.performCreate(Activity.java:6705)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Line 38 is db.execSQL(query); and line 57 is SQLiteDatabase db = getWritableDatabase();
change your query to this , you're missing some spaces and also you must remove the last comma from the query
#Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_PRODUCTS + "(" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_PRODUCTNAME + " TEXT, " +
COLUMN_VENUE + " TEXT, " +
COLUMN_DATEOFSTART + " TEXT, " +
COLUMN_DATEOFEND + " TEXT, " +
DURATION_WORKSHOP + " INTEGER, " +
COST_WORKSHOP + " INTEGER " +
");" ;
db.execSQL(query);
}
replace your query with this
String query = "CREATE TABLE " + TABLE_PRODUCTS + "(" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_PRODUCTNAME + " TEXT, " +
COLUMN_VENUE + " TEXT, " +
COLUMN_DATEOFSTART + " TEXT, " +
COLUMN_DATEOFEND + " TEXT, " +
DURATION_WORKSHOP + "INTEGER, " +
COST_WORKSHOP + "INTEGER " +
");" ;
actually you are putting one extra , at the end of query.
Change your query to this
String query = "CREATE TABLE " + TABLE_PRODUCTS + "(" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_PRODUCTNAME + " TEXT, " +
COLUMN_VENUE + " TEXT, " +
COLUMN_DATEOFSTART + " TEXT, " +
COLUMN_DATEOFEND + " TEXT, " +
DURATION_WORKSHOP + " INTEGER, " +
COST_WORKSHOP + " INTEGER " +
");" ;
You have formatting errors in there. An extra comma and two column names concatenated with their column types. See for e.g. how _costINTEGER should be _cost INTEGER
Change AUTOINCREMENT to AUTO_INCREMENT and remove extra ',' after column COST_WORKSHOP
String query = "CREATE TABLE " + TABLE_PRODUCTS + "(" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTO_INCREMENT, " +
COLUMN_PRODUCTNAME + " TEXT, " +
COLUMN_VENUE + " TEXT, " +
COLUMN_DATEOFSTART + " TEXT, " +
COLUMN_DATEOFEND + " TEXT, " +
DURATION_WORKSHOP + " INTEGER, " +
COST_WORKSHOP + " INTEGER " +
");" ;
Related
Below is the code which in which there is an error the app contains thousands of line of code so I am putting only the statement which is having a syntax error please see the bracket inserted on delete cascade statement SQLite statement ON DELETE CASCADE and how can I remove this error Any help is appreciated.
#Override
public void onCreate(SQLiteDatabase db) {
this.db = db;
final String SQL_CREATE_CATEGORIES_TABLE = "CREATE TABLE " +
ChaptersTable.TABLE_NAME + "( " +
ChaptersTable._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
ChaptersTable.COLUMN_NAME + " TEXT " +
")";
final String SQL_CREATE_SUBJECTS_TABLE = "CREATE TABLE " +
SubjectsTable.TABLE_NAME + "( " +
SubjectsTable._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
SubjectsTable.COLUMN_NAME + " TEXT " +
")";
final String SQL_CREATE_QUESTIONS_TABLE = "CREATE TABLE " +
QuestionsTable.TABLE_NAME + " ( " +
QuestionsTable._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
QuestionsTable.COLUMN_QUESTION + " TEXT, " +
QuestionsTable.COLUMN_OPTION1 + " TEXT, " +
QuestionsTable.COLUMN_OPTION2 + " TEXT, " +
QuestionsTable.COLUMN_OPTION3 + " TEXT, " +
QuestionsTable.COLUMN_ANSWER_NR + " INTEGER, " +
QuestionsTable.COLUMN_DIFFICULTY + " TEXT, " +
QuestionsTable.COLUMN_SUBJECT_ID+ " INTEGER, " +
"FOREIGN KEY(" + QuestionsTable.COLUMN_SUBJECT_ID+ ") REFERENCES " +
SubjectsTable.TABLE_NAME + "(" + SubjectsTable._ID + ")" + "ON DELETE CASCADE" /*(Here im having error)*/
+
QuestionsTable.COLUMN_CHAPTER_ID + " INTEGER, " +
"FOREIGN KEY(" + QuestionsTable.COLUMN_CHAPTER_ID + ") REFERENCES " +
ChaptersTable.TABLE_NAME + "(" + ChaptersTable._ID + ")" + "ON DELETE CASCADE" +
")";
db.execSQL(SQL_CREATE_CATEGORIES_TABLE);
db.execSQL(SQL_CREATE_QUESTIONS_TABLE);
db.execSQL(SQL_CREATE_SUBJECTS_TABLE);
fillCategoriesTable();
fillQuestionsTable();
fillSubjectsTable();
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + ChaptersTable.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + SubjectsTable.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + QuestionsTable.TABLE_NAME);
onCreate(db);
}
#Override
public void onConfigure(SQLiteDatabase db) {
super.onConfigure(db);
db.setForeignKeyConstraintsEnabled(true);
}
The correct syntax is to define the foreign keys where you define the column itself and not later:
final String SQL_CREATE_QUESTIONS_TABLE = "CREATE TABLE " +
QuestionsTable.TABLE_NAME + " ( " +
QuestionsTable._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
QuestionsTable.COLUMN_QUESTION + " TEXT, " +
QuestionsTable.COLUMN_OPTION1 + " TEXT, " +
QuestionsTable.COLUMN_OPTION2 + " TEXT, " +
QuestionsTable.COLUMN_OPTION3 + " TEXT, " +
QuestionsTable.COLUMN_ANSWER_NR + " INTEGER, " +
QuestionsTable.COLUMN_DIFFICULTY + " TEXT, " +
QuestionsTable.COLUMN_SUBJECT_ID+ " INTEGER " + "REFERENCES " +
SubjectsTable.TABLE_NAME + "(" + SubjectsTable._ID + ") " + "ON DELETE CASCADE," +
QuestionsTable.COLUMN_CHAPTER_ID + " INTEGER " + "REFERENCES " +
ChaptersTable.TABLE_NAME + "(" + ChaptersTable._ID + ") " + "ON DELETE CASCADE" +
")";
or all the foreign keys at the end of the statement:
final String SQL_CREATE_QUESTIONS_TABLE = "CREATE TABLE " +
QuestionsTable.TABLE_NAME + " ( " +
QuestionsTable._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
QuestionsTable.COLUMN_QUESTION + " TEXT, " +
QuestionsTable.COLUMN_OPTION1 + " TEXT, " +
QuestionsTable.COLUMN_OPTION2 + " TEXT, " +
QuestionsTable.COLUMN_OPTION3 + " TEXT, " +
QuestionsTable.COLUMN_ANSWER_NR + " INTEGER, " +
QuestionsTable.COLUMN_DIFFICULTY + " TEXT, " +
QuestionsTable.COLUMN_SUBJECT_ID+ " INTEGER, " +
QuestionsTable.COLUMN_CHAPTER_ID + " INTEGER, " +
"FOREIGN KEY(" + QuestionsTable.COLUMN_SUBJECT_ID+ ") REFERENCES " +
SubjectsTable.TABLE_NAME + "(" + SubjectsTable._ID + ") " + "ON DELETE CASCADE," +
"FOREIGN KEY(" + QuestionsTable.COLUMN_CHAPTER_ID + ") REFERENCES " +
ChaptersTable.TABLE_NAME + "(" + ChaptersTable._ID + ") " + "ON DELETE CASCADE" +//here must come '+' to remove syntax errors
")";
Im unable to create SQLite table.
Android Studio IDE shows me error on this line "Column constrains or Comma expected, got Text"
String CREATE_TABLE_CONTACTS = "CREATE TABLE " + Util.TABLE_NAME + "(" +
Util.KEY_ID + " INTEGER PRIMARY KEY," + Util.KEY_NAME + " TEXT," +
Util.KEY_PHONE_NUMBER + " TEXT" + ")";
IMO your code
String CREATE_TABLE_CONTACTS = "CREATE TABLE " + Util.TABLE_NAME + "(" +
Util.KEY_ID + " INTEGER PRIMARY KEY," + Util.KEY_NAME + " TEXT," +
Util.KEY_PHONE_NUMBER + " TEXT" + ")";
is ok problems belongs from Util.TABLE_NAME or Util.KEY_ID check here these key strings not having spaces
DO => user_name
DON'T => user name
If your columns happen to have whitespace or other reserved words, then you may try escaping them using double quotes:
String CREATE_TABLE_CONTACTS = "CREATE TABLE \"" + Util.TABLE_NAME + "\" (" +
"\"" + Util.KEY_ID + "\" INTEGER PRIMARY KEY, \"" + Util.KEY_NAME + "\" TEXT, \"" +
Util.KEY_PHONE_NUMBER + "\" TEXT" + ")";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "addToCart_db";
public static final String TABLE_NAME = "addToCart";
public static final String COLUMN_ID = "id";
public static final String COLUMN_PRODUCT_ID = "product_id";
public static final String COLUMN_QTY = "qty";
public static final String COLUMN_PRICE = "price";
public static final String CREATE_TABLE =
"CREATE TABLE " + TABLE_NAME + "("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ COLUMN_PRODUCT_ID + " TEXT,"
+ COLUMN_PRICE + " TEXT,"
+COLUMN_QTY +" TEXT)";
try it, this formatting create table
I have researched other instances of this error all morning but nothing i've tried so far has worked. It could be something obvious as I am quite new to this.
I am trying to return the results of the GET_ALL_INGREDIENTS query. Which I will then put into a 2d array, but you don't need to worry about that. My TABLE_RECIPES table works fine.
SQLiteException: no such table: TABLE_INGREDIENTS (code 1): , while compiling: SELECT INGR...etc....
Which occurs on the last line of this bit of code:
public String[][] getRecipeIngredients(int id) {
String GET_ALL_INGREDIENTS = "SELECT INGREDIENT_NAME, INGREDIENT_QUANTITY, INGREDIENT_UNIT " +
"FROM TABLE_INGREDIENTS " +
"INNER JOIN TABLE_RECIPE_INGREDIENTS ON TABLE_RECIPE_INGREDIENTS.INGREDIENT_ID=TABLE_INGREDIENTS.INGREDIENT_ID " +
"WHERE RECIPE_INGREDIENTS.RECIPE_ID=" + id;
db = new MyDBHandler(mContext);
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(GET_ALL_INGREDIENTS, null);
Table Creation:
final String CREATE_TABLE_RECIPES = "CREATE TABLE IF NOT EXISTS " +
TABLE_RECIPES + "(" +
RECIPE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
RECIPE_NAME + " TEXT, " +
RECIPE_INSTRUCTIONS + " TEXT " +
")";
final String CREATE_TABLE_INGREDIENTS = "CREATE TABLE IF NOT EXISTS " +
TABLE_INGREDIENTS + "(" +
INGREDIENT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
INGREDIENT_NAME + " TEXT NOT NULL UNIQUE " +
")";
final String CREATE_TABLE_RECIPE_INGREDIENTS = "CREATE TABLE IF NOT EXISTS " +
TABLE_RECIPE_INGREDIENTS + "(" +
RECIPE_ID + " INTEGER NOT NULL, " +
INGREDIENT_ID + " INTEGER NOT NULL, " +
INGREDIENT_QUANTITY + " REAL, " +
INGREDIENT_UNIT + " TEXT, " +
"PRIMARY KEY (" + RECIPE_ID + "," + INGREDIENT_ID + "), " +
"FOREIGN KEY (" + RECIPE_ID + ") REFERENCES " + TABLE_RECIPES + "(" + RECIPE_ID + "), " +
"FOREIGN KEY (" + INGREDIENT_ID + ") REFERENCES " + TABLE_INGREDIENTS + "(" + INGREDIENT_ID + ")" +
")";
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_RECIPES);
db.execSQL(CREATE_TABLE_INGREDIENTS);
db.execSQL(CREATE_TABLE_RECIPE_INGREDIENTS);
}
Thank you for reading and I really appreciate any help i can get with this.
TABLE_INGREDIENTS is a variable. It's value is likely not "TABLE_INGREDIENTS" that is a string literal. So you might want to change
"FROM TABLE_INGREDIENTS " +
to
"FROM " + TABLE_INGREDIENTS +
(You have a number of other similar issues in your SQL too.)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I got error for creating sqlite db in android.
My code is:
public static final String TABLE_NAME = "user";
public static final String COL1_USER_ID = "USER_ID";
public static final String COL2_USER_NAME = "USER_NAME";
public static final String COL3_IMEI_CODE = "IMEI_CODE";
public static final String COL4_REGISTRATION_ID = "REGISTRATION_ID";
public static final String COL5_MOBILE_NUMBER = "MOBILE_NUMBER";
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "(" + _ID + " INTEGER PRIMARY KEY,"+ COL1_USER_ID + TEXT_TYPE + COMMA_SEP + COL2_USER_NAME + TEXT_TYPE
+ COMMA_SEP + COL3_IMEI_CODE + TEXT_TYPE + COMMA_SEP + COL4_REGISTRATION_ID + VARCHAR_TYPE + COMMA_SEP + COL5_MOBILE_NUMBER + TEXT_TYPE + COMMA_SEP + ")";
Error message is:
android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: CREATE TABLE user(_id INTEGER PRIMARY KEY,USER_ID TEXT,USER_NAME TEXT,IMEI_CODE TEXT,REGISTRATION_ID VARCHAR(255),MOBILE_NUMBER TEXT,)
How to solve this?
You should remove + COMMA_SEP at last
Corrected
String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "(" + _ID + " INTEGER PRIMARY KEY,"+ COL1_USER_ID + TEXT_TYPE + COMMA_SEP + COL2_USER_NAME + TEXT_TYPE
+ COMMA_SEP + COL3_IMEI_CODE + TEXT_TYPE + COMMA_SEP + COL4_REGISTRATION_ID + VARCHAR_TYPE + COMMA_SEP + COL5_MOBILE_NUMBER + TEXT_TYPE + ")";
Replace below lines of code instead of yours.
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "(" + _ID + " INTEGER PRIMARY KEY,"+ COL1_USER_ID + TEXT_TYPE + COMMA_SEP + COL2_USER_NAME + TEXT_TYPE
+ COMMA_SEP + COL3_IMEI_CODE + TEXT_TYPE + COMMA_SEP + COL4_REGISTRATION_ID + VARCHAR_TYPE + COMMA_SEP + COL5_MOBILE_NUMBER + TEXT_TYPE + ")";
There is one more comma at last, actually there is no need of it.
Error
12-22 14:30:52.329 1261-1261/com.TrackApp.trackapp E/SQLiteLog﹕ (1) near "Throw": syntax error
12-22 14:30:52.329 1261-1261/com.TrackApp.trackapp D/AndroidRuntime﹕ Shutting down VM
12-22 14:30:52.339 1261-1261/com.TrackApp.trackapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40a13300)
12-22 14:30:52.389 1261-1261/com.TrackApp.trackapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.database.sqlite.SQLiteException: near "Throw": syntax error (code 1): , while compiling: INSERT INTO Athletes (ID, First_Name, Last_Name, Age, Gender, Event, Tier) VALUES (0, Joe, Richards, 20, Male, Discus Throw, 2);
I keep getting this error when trying to add a new athlete to my database. Could someone please figure out what I am doing wrong. I am almost certain all of my sql statements are correct. I think it thinks that it is creating a new column under events for whatever is from the athlete object but I don't know
private static final String DATABASE_NAME = "AthletesDB";
private static final int VERSION = 1;
private static final String TABLE_NAME = "Athletes";
private static final String COLUMN_ID = "ID";
private static final String COLUMN_FIRST_NAME = "First_Name";
private static final String COLUMN_LAST_NAME = "Last_Name";
private static final String COLUMN_AGE = "Age";
private static final String COLUMN_GENDER = "Gender";
private static final String COLUMN_EVENT = "Event";
private static final String COLUMN_TIER = "Tier";
private static final String[] COLUMNS = {"ID", "First_Name", "Last_Name", "Age", "Gender", "Event", "Tier"};
private static final String TABLE_CREATE = "CREATE TABLE " + TABLE_NAME + "( " + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ COLUMN_FIRST_NAME + " VARCHAR(20), " + COLUMN_LAST_NAME + " VARCHAR(20), " + COLUMN_AGE + " INTEGER, " +
COLUMN_GENDER + " VARCHAR(20), " + COLUMN_EVENT + " VARCHAR(20), " + COLUMN_TIER + " INTEGER " + ")";
public MySQLiteHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, DATABASE_NAME, null, VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_CREATE);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CREATE);
onCreate(db);
}
public void addAthlete(Athlete athlete){
SQLiteDatabase db = this.getWritableDatabase();
/*ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_ID, athlete.getID());
contentValues.put(COLUMN_FIRST_NAME, athlete.getFirstName());
contentValues.put(COLUMN_LAST_NAME, athlete.getLastName());
contentValues.put(COLUMN_AGE, athlete.getAge());
contentValues.put(COLUMN_GENDER, athlete.getGender());
contentValues.put(COLUMN_EVENT, athlete.getEvent());
contentValues.put(COLUMN_TIER, athlete.getTier());*/
// db.insert(TABLE_NAME, null, contentValues);
db.execSQL("INSERT INTO " + TABLE_NAME + " (" + COLUMN_ID + ", " + COLUMN_FIRST_NAME + ", " + COLUMN_LAST_NAME
+ ", " + COLUMN_AGE + ", " + COLUMN_GENDER + ", " + COLUMN_EVENT + ", " + COLUMN_TIER + ")" +
" VALUES " + "(" + athlete.getID() + ", " + athlete.getFirstName()
+ ", " + athlete.getLastName() + ", " + athlete.getAge() + ", " + athlete.getGender() + ", " +
athlete.getEvent() + ", " + athlete.getTier() + ");");
db.close();
}
You should surround the string values you insert with single quotes. The exception is thrown because you have whitespace in your literal "Discus Throw". Try the following:
db.execSQL("INSERT INTO "
+ TABLE_NAME + " ("
+ COLUMN_ID + ", "
+ COLUMN_FIRST_NAME + ", "
+ COLUMN_LAST_NAME + ", "
+ COLUMN_AGE + ", "
+ COLUMN_GENDER + ", "
+ COLUMN_EVENT + ", "
+ COLUMN_TIER + ")" +
" VALUES " + "("
+ athlete.getID() + ", "
+ athlete.getFirstName() + ", "
+ athlete.getLastName() + ", "
+ athlete.getAge() + ", "
+ athlete.getGender() + ", "
+ "'" + athlete.getEvent() + "'" + ", "
+ athlete.getTier() + ");");
which gives you
INSERT INTO Athletes (ID, First_Name, Last_Name, Age, Gender, Event, Tier)
VALUES (0, Joe, Richards, 20, Male, 'Discus Throw', 2);
Surround each entry of type TEXT in VALUES with single quotes.
For example,
" VALUES ('" + athlete.getFirstName() + "')"
Or, written out:
" VALUES ('Bob')"