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?
I would guess that "Transaction" is a key word that you are not allowed to use. Try changing the name to something else.
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
精彩评论