1

I am always getting this error.I think query is allright.What is problem?

"Caused by: android.database.sqlite.SQLiteException: near "to": syntax error: , while compiling: create table Messages(_id integer , msgdesc text ,date timestamp not null, createdby integer not null, to integer not null); "

This is my code:

public class ContactListDB extends SQLiteOpenHelper {


private static final int DATABASE_VERSION = 2;
private static final String DATABASE_NAME = "MobileMerch";

// Database creation SQL statement
private static final String CREATE_MERCH  = "create table Merchendiser" +
        "(_id integer primary key, name text not null,surname text not null,username text not null);";

// Database creation SQL statement
private static final String CREATE_MESSAGES = "create table Messages" +
        "(_id integer , msgdesc text ,date timestamp  not null, createdby integer not null, to integer not null);";



public ContactListDB(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}    

public void onCreate(SQLiteDatabase db) {

    db.execSQL(CREATE_MERCH);
    db.execSQL(CREATE_MESSAGES);


}
2
  • 1
    maybe "to" is reserved name? Commented Feb 1, 2013 at 7:22
  • i try my sql statements in the console and edit them in notepad++. this shows me what words are reserved and so i bypass program crashes and other bugs that takes some time to debug Commented Feb 1, 2013 at 7:24

1 Answer 1

5

TO is a reserved word. Either rename your column (recommended) or escape it by enclosing it in double-quotes (e.g. "to").

See also: http://www.sqlite.org/lang_keywords.html

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

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.