shehanaz
shehanaz

Reputation: 31

syntax error in creating a table in android

private static final String DATABASE_TABLE_TRANS = "Transaction";   
private static final String DATABASE_CREATE_TRANS = 
       "create table " + DATABASE_TABLE_TRANS + "(_id integer primary key autoincrement, "
       + "Amount text not null, " + "Name_of_bank text unique not null, " 
       + "Trans_Time text not null);";

 public void onCreate(SQLiteDatabase db) 
        {
            System.out.println("oncreate of dbbbbbbbbbbbbbbbbb");
            db.execSQL(DATABASE_CREATE_TRANS);
        }

while running I get the error:

 08-05 14:40:15.187: ERROR/AndroidRuntime(5362):
 android.database.sqlite.SQLiteException: near "Transaction": syntax
 error: create table Transaction(_id integer primary key autoincrement,
 Amount text not null, Name_of_bank text unique not null, Trans_Time
 text not null);

What have I done wrong?

Upvotes: 2

Views: 1352

Answers (2)

Avi Kumar
Avi Kumar

Reputation: 4433

Care must be taken when using SQLite keywords as identifier names.As a general rule of thumb you should try to avoid using any keywords from the SQL language as identifiers, although if you really want to do so, they can be used providing they are enclosed in square brackets. For instance the following statement will work just fine, but this should not be mimicked on a real database sqlite> CREATE TABLE [TABLE] ( ...> [SELECT], ...> [INTEGER] INTEGER, ...> [FROM], ...> [TABLE] ...> );

here is a link for sqlite keywords

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

and here you can find naming conventions for databses

http://www.pearsonhighered.com/assets/hip/us/hip_us_pearsonhighered/samplechapter/067232685X.pdf

Upvotes: 1

Pikaling
Pikaling

Reputation: 8312

I would guess that "Transaction" is a key word that you are not allowed to use. Try changing the name to something else.

Upvotes: 5

Related Questions