Reputation: 374
So I have multiple tables in my database. I have an Employee table that that has 2 foreign keys with the ID's from Owner and Account tables but I got an error following the code below:
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 +"));";
I have also tried this one in adding multiple foreign keys but it also got me an error:
....
+ COL_OWNER_ID + "INTEGER REFERENCES" + OWNER +
+ COL_ACCT_ID + "INTEGER REFERENCES" + ACCOUNT+ ")";
Can you please tell me what's wrong with this code? Thanks
Error: error: ';' expected error: invalid method declaration; return type required error: illegal start of type error: ';' expected
error: unclosed string literal error: unclosed string literal error: expected
Upvotes: 0
Views: 81
Reputation: 17725
This is a syntax error in the java source, add a few "
:
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 +"));";
Upvotes: 1