我编写此字符串是为了在 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/