Reputation: 47
I am getting
>android.database.sqlite.SQLiteException: near "tb_quiz": syntax error (code 1):
in Line
> @Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE table IF NOT EXISTS tb_quiz");
Log.e("--------------", "file table created");
}
please help some one....thanks in advance.
Upvotes: 0
Views: 603
Reputation: 377
"CREATE TABLE IF NOT EXISTS tb_quiz "
+ "(" + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_COMMENT+ " text");
You should provide the schema of the table.
Upvotes: 0
Reputation: 3348
Try this,
public class DataBaseHelper extends SQLiteOpenHelper {
private static final String TAG = "DataBaseHelper";
// Database Name
private static final String DATABASE_NAME = "MYAPP";
// Database Version
private static final int DATABASE_VERSION = 1;
private static final String TABLE_USER = "user_info";
// Common column names TABLE_USER
private static final String KEY_ID = "id";
private static final String KEY_USERNAME = "u_name";
private static final String KEY_PASSWORD = "u_pwd";
private static final String CREATE_TABLE_USER = "CREATE TABLE IF NOT EXISTS " + TABLE_USER
+ "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ KEY_USERNAME + " TEXT,"
+ KEY_PASSWORD + " TEXT"
+ ")";
public DataBaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// creating required tables
db.execSQL(CREATE_TABLE_USER);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + CREATE_TABLE_USER);
// Create tables again
onCreate(db);
}
}
Upvotes: 0
Reputation: 265
Please use following query for creating table String CREATE_CLASS_TABLE = "CREATE TABLE class_table(class_id INTEGER, class_name TEXT)"
Upvotes: 0
Reputation: 831
Table cannot be empty, try writing some columns as follows:
CREATE TABLE IF NOT EXISTS table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);
Upvotes: 1
Reputation: 75645
You cannot create empty table. At least one column must be specified: https://sqlite.org/lang_createtable.html
Upvotes: 1