安卓数据库异常

标签 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="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 关键字的完整列表,请查看 here .

关于安卓数据库异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13498454/

相关文章:

android - 无法解析 IntelliJ 中的符号 BitmapFactory.decodeResource

所有应用程序上 onResume() 的 Android 监听器

java - 无法访问原始文件夹中的音频

c++ - C++中sqlite3回调函数的正确使用

winforms - 使用嵌入式 sqlite 部署 winform 应用程序

iphone - 如何插入到iPhone sdk中的表(sqlite db)

android - 如何布局我的 android 应用程序?

android - 附加音频文件作为 android 中的彩信

python - 如何从 sqlite 中获取一个 µ 字符并放到网页上?

android - 我应该使用哪种类型的数据库?