My table is :
Statement s5 = conn.createStatement();
ResultSet res5 = s5.executeQuery("Select name from sqlite_master where type = 'table' and name = 'actor_director'");
if(!res5.next()){
Statement ad = conn.createStatement();
ad.executeUpdate("create table actor_director(actor_ID integer, director_ID integer,"
+ "foreign key(actor_ID) references actor(actor_ID) ON UPDATE CASCADE ON DELETE CASCADE,"
+ "foreign key(director_ID) references director(director_ID)) ON UPDATE CASCADE ON DELETE CASCADE");
}
and i also did :
public static Connection getConnection() throws SQLException{
SQLiteConfig config = new SQLiteConfig();
config.enforceForeignKeys(true);
conn = DriverManager.getConnection("jdbc:sqlite:movieandtvseries.db", config.toProperties());
return conn;
}
When i run the program i get this error :
SQLiteException: [SQLITE_ERROR] SQL error or missing database (near "ON": syntax error)
You seem to have a typo in the line:
+ "foreign key(director_ID) references director(director_ID)) ON UPDATE CASCADE ON DELETE CASCADE");
There is an extra ')' after 'director_ID'. There is also a ')' missing after the last 'CASCADE' and before the double quote.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.