0

it say that something is wrong with createTable string,

My database class....

class DataBase extends SQLiteOpenHelper{
            private final static String createTable="CREATE TABLE "+Keys.Database.TableName+
                    "("+Keys.Database._Id+" INTEGER PRIMARY KEY AUTOINCREMENT, "
                    +Keys.Database.Date+" TEXT(50), "
                    +Keys.Database.Type+" TEXT(50), "
                    +Keys.Database.City+" TEXT(100);";
            private final static String dropTable = "DROP TABLE IF EXISTS"+Keys.Database.TableName+";";

            private DataBase(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
                super(context, name, factory, version);
            }

            private DataBase(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
                super(context, name, factory, version, errorHandler);
            }


            @Override
            public void onCreate(SQLiteDatabase db) {

                    db.execSQL(createTable);

            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                db.execSQL(dropTable);
                onCreate(db);
            }
        }

and here is some piece of code from where i'm trying to create table

public void writeHistory(String date, String type, String city){
        database = new DataBase(context,Keys.Database.DataBaseName,null,Keys.Database.Version);
        SQLiteDatabase sqLiteDatabase = database.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(Keys.Database.Date,date);
        contentValues.put(Keys.Database.Type,type);
        contentValues.put(Keys.Database.City, city);
        long i=sqLiteDatabase.insert(Keys.Database.TableName,null,contentValues);
        if (i<0){
            Toast.makeText(MyApplication.getMyAppContext(),"History insertion FAILED",Toast.LENGTH_LONG).show();
        }
        else {
            Toast.makeText(MyApplication.getMyAppContext(),"History insertion SUCCESSFUL",Toast.LENGTH_LONG).show();
        }
    }

I'm getting that error while creating the table, please help... thanks in advance..

1
  • 1
    +Keys.Database.City+" TEXT(100);"; - delete the first semicolon. Commented Sep 25, 2015 at 13:52

1 Answer 1

1

oops found it... :p

private final static String createTable="CREATE TABLE "+Keys.Database.TableName+
                    "("+Keys.Database._Id+" INTEGER PRIMARY KEY AUTOINCREMENT, "
                    +Keys.Database.Date+" TEXT(50), "
                    +Keys.Database.Type+" TEXT(50), "
                    +Keys.Database.City+" TEXT(100));";

it was just a stupid bracket..

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

1 Comment

By the way, the useless semicolon (;) can be avoided.

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.