0

Help me please,I am don't understand it .i will be create data base but it error.please i will be end example project next night .please help me

code

public class FriendsDBHelper extends SQLiteOpenHelper {

    public static int TABLE_VERSION = 1;
    public static String TABLE_NAME ="table_f";
    public static String TABLE_KEY_ID = "id";
    public static String TABLE_KEY_FNAME = "fname";
    public static String TABLE_KEY_LNAME = "lname";
    public static String TABLE_KEY_NNAME = "nickname";

    public static String TABLE_CREATE_SQL = "CREATE TABLE "+TABLE_NAME+" ("+
                                            ""+TABLE_KEY_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
                                            ""+TABLE_KEY_FNAME+"TEXT(20), "+
                                            ""+TABLE_KEY_LNAME+"TEXT(20), "+
                                            ""+TABLE_KEY_NNAME+"TEXT(20), "+
                                            ") ";
    //Constructor
    public FriendsDBHelper(Context context) {
        super(context, TABLE_NAME, null, TABLE_VERSION);

    }
    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(TABLE_CREATE_SQL);
    }

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

        db.execSQL("DROP TABLE "+TABLE_NAME);
        onCreate(db);
        Log.i("Friends DB Helper","Table upgrade form "+ oldVersion +" to "+newVersion);
    }
}

2 Answers 2

3

You need whitespace between column names and types here:

""+TABLE_KEY_FNAME+"TEXT(20), "+
""+TABLE_KEY_LNAME+"TEXT(20), "+
""+TABLE_KEY_NNAME+"TEXT(20), "+

To fix another syntax error, remove the , after the last column spec.

Better:

""+TABLE_KEY_FNAME+" TEXT(20), "+
""+TABLE_KEY_LNAME+" TEXT(20), "+
""+TABLE_KEY_NNAME+" TEXT(20) "+

The parens are syntactically valid (but semantically ignored) for column type but not for column name.

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

Comments

0

You have an extra "," at the end of create table command.

""+TABLE_KEY_NNAME+"TEXT(20), "+

Remove that.

Also ""+TABLE_KEY_FNAME+"TEXT(20), "+ it will evaluate as ""+TABLE_KEY_FNAMETEXT(20), "+ i.e. without space between field and type, so add a space like:

""+TABLE_KEY_FNAME+" TEXT(20), "+

Similar changes applies to other field definition as well.

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.