所以我的数据库中有多个表。我有一个 Employee 表,该表具有2个外键,其ID来自 Owner 和 Account 表,但是在以下代码中出现错误:
private static final String CREATE_TABLE_EMPLOYEE = " CREATE TABLE "
+ EMPLOYEE + "("
+ COL_EMP_ID + "INTEGER PRIMARY KEY AUTOINCREMENT,"
+ COL_EMP_LNAME + "TEXT,"
+ COL_EMP_FNAME + "TEXT,"
+ COL_EMP_IMG + "INTEGER,"
+ COL_EMP_DOB + "DATE,"
+ COL_EMP_GENDER + "TEXT,"
+ COL_EMP_PHONE + "INTEGER,"
+ FOREIGN KEY("+ COL_OWNER_ID +") REFERENCES "+ OWNER +"("+ COL_OWNER_ID +"), "
+ FOREIGN KEY("+ COL_ACCT_ID +") REFERENCES "+ ACCOUNT +"("+ COL_ACCT_ID +"));";
我也尝试过添加多个外键,但这也给我一个错误:
....
+ COL_OWNER_ID + "INTEGER REFERENCES" + OWNER +
+ COL_ACCT_ID + "INTEGER REFERENCES" + ACCOUNT+ ")";
您能告诉我这段代码有什么问题吗?谢谢
错误:错误:“;”预期的错误:方法声明无效;返回 键入所需的错误:非法开始键入错误:';'预期
错误:未封闭的字符串文字错误:未封闭的字符串文字错误: 预期的
答案 0 :(得分:1)
这是Java源代码中的语法错误,请添加一些"
:
private static final String CREATE_TABLE_EMPLOYEE = " CREATE TABLE "
+ EMPLOYEE + "("
+ COL_EMP_ID + "INTEGER PRIMARY KEY AUTOINCREMENT,"
+ COL_EMP_LNAME + "TEXT,"
+ COL_EMP_FNAME + "TEXT,"
+ COL_EMP_IMG + "INTEGER,"
+ COL_EMP_DOB + "DATE,"
+ COL_EMP_GENDER + "TEXT,"
+ COL_EMP_PHONE + "INTEGER,"
+ "FOREIGN KEY("+ COL_OWNER_ID +") REFERENCES "+ OWNER +"("+ COL_OWNER_ID +"), "
+ "FOREIGN KEY("+ COL_ACCT_ID +") REFERENCES "+ ACCOUNT +"("+ COL_ACCT_ID +"));";