java - 用于在 SQLite 中创建完整数据库的字符串

标签 java android string sqlite

我编写此字符串是为了在 SQLite 中创建数据库,但在“CREATE corso”之前出现错误 CREATE Unexpected。这是字符串:

static final String DATABASE_CREAZIONE =
        "CREATE TABLE utente (id integer primary key autoincrement, "
                + "nome text not null, cognome text not null, "
                + "email text not null, password text not null);"
                + "CREATE TABLE corso (id integer primary key autoincrement," +
                "nome text not null);" +
                "CREATE TABLE prenotazione (id_utente integer primary key autoincrement, "
                + "id_docente integer primary key autoincrement, data DATETIME not null);"+
                "CREATE TABLE docenza (id integer primary key autoincrement, "
                + "nome_corso text not null, nome_prof text not null); "+
                "CREATE TABLE professore (id integer primary key autoincrement, "
                + "nome text not null, cognome text not null); ";

最佳答案

这只是 Android Studio IDE 发出警告,但有正当理由。

Android SQLiteDatabase execSQL() 通常用于执行 SQL,这样一次只执行一条语句。 ; 之后的任何内容都将被忽略。

您需要将 SQL 拆分为单独的 execSQL() 调用。这也将摆脱 IDE 警告并执行 SQL 的其他部分,以便您可以检测运行时问题,如 Boken 在他的回答中报告的那样。

关于java - 用于在 SQLite 中创建完整数据库的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55065817/

相关文章:

java - 在 Java 中的文本周围添加 HTML 标签

r - 搜索列名称中的字符串并检索每行的相应值

java - Hibernate updatable = false UUID 字段已更新

java - 在我的 android 项目中遇到 nullPointerExecption

以反冲结尾的 Java 属性值

java - 如何限制用户在数据库中多次写入

javascript - 如何获得分割字符串 "/"和 "/something"的不同长度

java - 以编程方式从 TabLayoutPanel 中删除选项卡,GWT

android - 我们如何打开TextView的链接到Webview

PHP用RSA解密加密密码,Android看到一些垃圾数据加上解密后的真实数据