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?
我做错了什么?
2 个解决方案
#1
5
I would guess that "Transaction" is a key word that you are not allowed to use. Try changing the name to something else.
我猜“交易”是一个不允许使用的关键词。尝试将名称更改为其他名称。
#2
1
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] ...> );
使用SQLite关键字作为标识符名称时必须小心。作为一般经验法则,您应该尽量避免使用SQL语言中的任何关键字作为标识符,尽管如果您真的想这样做,可以使用它们,前提是它们是封闭的在方括号内。例如,以下语句可以正常工作,但不应在真实数据库上模仿sqlite> CREATE TABLE [TABLE](...> [SELECT],...> [INTEGER] INTEGER,...> [ FROM],...> [TABLE] ...>);
here is a link for sqlite keywords
这是sqlite关键字的链接
http://www.sqlite.org/lang_keywords.html
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
http://www.pearsonhighered.com/assets/hip/us/hip_us_pearsonhighered/samplechapter/067232685X.pdf
#1
5
I would guess that "Transaction" is a key word that you are not allowed to use. Try changing the name to something else.
我猜“交易”是一个不允许使用的关键词。尝试将名称更改为其他名称。
#2
1
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] ...> );
使用SQLite关键字作为标识符名称时必须小心。作为一般经验法则,您应该尽量避免使用SQL语言中的任何关键字作为标识符,尽管如果您真的想这样做,可以使用它们,前提是它们是封闭的在方括号内。例如,以下语句可以正常工作,但不应在真实数据库上模仿sqlite> CREATE TABLE [TABLE](...> [SELECT],...> [INTEGER] INTEGER,...> [ FROM],...> [TABLE] ...>);
here is a link for sqlite keywords
这是sqlite关键字的链接
http://www.sqlite.org/lang_keywords.html
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
http://www.pearsonhighered.com/assets/hip/us/hip_us_pearsonhighered/samplechapter/067232685X.pdf