0

I can not create a table. It shows that the database is created and I can also insert a row, but the table is not created.

public class DatabaseOperations extends SQLiteOpenHelper {

public static final int Database_version = 2;

public static final String Tag = DatabaseOperations.class.getSimpleName();

private static final String SQL_CREATE_ENTRIES =
        "CREATE TABLE " + TableData.TableInfo.TABLE_NAME + " (" +
                TableData.TableInfo.USER_ID + " INTEGER PRIMARY KEY," +
                TableData.TableInfo.USER_PASS +" TEXT "+ "," +
                TableData.TableInfo.USER_EMAIL +" TEXT "+ ");";

public DatabaseOperations(Context context) {
super(context, TableData.TableInfo.DATABASE_NAME, null,Database_version);
    Log.d("Tag", "Database created");
}

@Override
public void onCreate(SQLiteDatabase sdb) {
    sdb.execSQL(SQL_CREATE_ENTRIES);
    Log.d("Tag", "Table created");

}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}

public void putInformation(DatabaseOperations drop, String name, String   pass, String email) {
    SQLiteDatabase SQ = drop.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put(TableData.TableInfo.USER_ID, name);
    cv.put(TableData.TableInfo.USER_PASS, pass);
    cv.put(TableData.TableInfo.USER_EMAIL, email);
    long k = SQ.insert(TableData.TableInfo.TABLE_NAME, null, cv);
    Log.d("Tag", "inert a row");
 }

public Cursor getInformation(DatabaseOperations dop) {
    SQLiteDatabase SQ = dop.getReadableDatabase();
    String[] coloumns = {TableData.TableInfo.USER_ID,  TableData.TableInfo.USER_PASS, TableData.TableInfo.USER_EMAIL};
    Cursor CR = SQ.query(TableData.TableInfo.TABLE_NAME, coloumns, null, null, null, null, null);
    return CR;
}
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Mohammad
  • 31
  • 5
  • 1
    your sql staement has a mistake there `");";`. remove the first `;` – Aelop Dec 14 '16 at 09:47
  • I don't think it's the problem. The first semicolon is there to show the end of the SQL Statement, so it's right. – Elcan Dec 14 '16 at 09:49
  • The `;` is only **useless** in a SQLite statement (because no multiple statements will be processed), **but not harmful**. – Phantômaxx Dec 14 '16 at 09:51

2 Answers2

1

You're missing a , between USER_EMAIL and USER_PASS columns in the CREATE TABLE.

After adding it you can uninstall your app to recreate the database. When is SQLiteOpenHelper onCreate() / onUpgrade() run?

Community
  • 1
  • 1
laalto
  • 150,114
  • 66
  • 286
  • 303
0

You miss comma in USER PASS type.Uninstall the application and install it again each time you add something new to sqlite database because the table structure has been changed.So you need to reinstall the new application .

The code should be like this

private static final String SQL_CREATE_ENTRIES = "CREATE TABLE " + TableData.TableInfo.TABLE_NAME + " (" + TableData.TableInfo.USER_ID + " INTEGER PRIMARY KEY," + TableData.TableInfo.USER_PASS +" TEXT ,"+ "," + TableData.TableInfo.USER_EMAIL +" TEXT "+ ")";

prsandroid
  • 88
  • 2
  • 10