我正在尝试在 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="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);
}
});
}