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;
}
}
3
  • 1
    your sql staement has a mistake there ");";. remove the first ; Commented Dec 14, 2016 at 9: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. Commented Dec 14, 2016 at 9:49
  • The ; is only useless in a SQLite statement (because no multiple statements will be processed), but not harmful. Commented Dec 14, 2016 at 9:51

2 Answers 2

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?

Sign up to request clarification or add additional context in comments.

Comments

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 "+ ")";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.