0

I'm creating an application to input input string values from EditText into a SQLite database. When running the app through the simulator, a logcat error message is received when the database will be created initially. The logcat error message is below.

01-23 16:47:39.613: E/Database(1386): Failure 1 (near "existinfoTable": syntax error) on 0x1392b8 when preparing 'create table if not existinfoTable(_idinterger primary key,sNametext not null,wUrltext not null,uNametext not null,pWordtext not null);'.

The OnCreate method it is referring to is below. I'm not sure what syntax error is causing the problem. any help would be appreciated.

public void onCreate(SQLiteDatabase db) {
    String sqlDataStore = "create table if not exist" +
        TABLE_NAME_INFOTABLE + "("+ BaseColumns._ID + "interger primary key autoincrement,"
        + COLUMN_NAME_SITE + "text not null,"
        + COLUMN_NAME_ADDRESS + "text not null,"
        + COLUMN_NAME_USERNAME + "text not null,"
        + COLUMN_NAME_PASSWORD + "text not null),";
    db.execSQL(sqlDataStore);
}

1 Answer 1

10

From the looks of it, you mispelled 'integer' and it looks like you need a spaces before 'integer', after 'exist' (I think it should be 'exists') and before '('. So....

String sqlDataStore = "create table if not exists " +
        TABLE_NAME_INFOTABLE + " ("+ BaseColumns._ID + " integer primary key autoincrement,"
                + COLUMN_NAME_SITE + "text not null,"
                + COLUMN_NAME_ADDRESS + "text not null,"
                + COLUMN_NAME_USERNAME + "text not null,"
                + COLUMN_NAME_PASSWORD + "text not null)";

You can also omit the ',' or ';' at the end of the statement.

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

5 Comments

Also needs a space before each text not null
Thank for catching those but I still get the same error. Here is a copy of my logcat.
01-23 18:43:03.017: E/AndroidRuntime(1578): android.database.sqlite.SQLiteException: near "exist": syntax error: create table if not exist infoTable(_idinteger primary key autoincrement,sName text not null,wUrl text not null,uName text not null,pWord text not null), 01-23 18:43:03.017: E/AndroidRuntime(1578): at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method) 01-23 18:43:03.017: E/AndroidRuntime(1578): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1610)
Judging from the error, it looks like the only change you made was to correct the spelling of 'integer' and add a space before 'text'. It's kind of subtle but notice how in my answer there are spaces in some of the quotations. I was able to create the table in a test database and the only thing you need to fix is to change 'exist' to 'exists' and to add a space between '_id' and 'integer'
Truly Amazing!!!...cant believe I missed that. Its the little things that have the biggest impact. Thank YOU!!!!

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.