android数据库异常
我正在尝试在android上创建数据库,运行时引发异常:android数据库异常,android,sqlite,Android,Sqlite,我正在尝试在android上创建数据库,运行时引发异常: Database - Failure 1 (near "integer" : syntax error) on 0x1ac028 when preparing 'create table list1 (id integer Primary key autoincrement, task text not null, check integer not null)' 我不明白为什么会这样。这是我的代码: String dbName="pr
Database - Failure 1 (near "integer" : syntax error) on 0x1ac028 when preparing 'create table list1 (id integer Primary key autoincrement, task text not null, check integer not null)'
我不明白为什么会这样。这是我的代码:
String dbName="projectDatabase";
String tableName="List1";
String TableStructure="create table " + tableName +" (id integer Primary key autoincrement, task text not null, check integer not null)";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button cb = (Button) findViewById(R.id.creatbutton);
cb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try{
SQLiteDatabase ldb = openOrCreateDatabase(dbName, Context.MODE_PRIVATE, null);
ldb.execSQL(TableStructure);}catch(Exception e){
Toast.makeText(DsTest2Activity.this, "Failed", Toast.LENGTH_LONG).show();
}
Intent list = new Intent(DsTest2Activity.this,List.class);
startActivity(list);
}
});
}
check
是一个SQLite关键字。不能将其用作表名或列名
将列名更改为其他名称,错误就会消失
String TableStructure="create table " + tableName +" (id integer Primary key autoincrement, task text not null, checknum integer not null)";
要获得当前SQLite关键字的完整列表,请查看。下午好,将id integer主键自动递增,放入代码中,例如:
CREATE TABLE tabela(_idinteger主键自动递增,任务文本不为null,check integer不为null)代码>要将关键字直接用作列名,请引用它:
..., "check" integer not null)
我认为它的check id在create语句中不为null。一旦选中它,check
就是一个SQLite关键字。。。它不能用作表名或列名。+1 True,但必须转义引号(在OP使用它的方法中使用)。只需更改列名即可更简单:p