[英]Can't add foreign key constraints in sqlite using java
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'. 在“ director_ID”之后还有一个额外的“)”。 There is also a ')' missing after the last 'CASCADE' and before the double quote.
在最后一个“ CASCADE”之后和双引号之前还缺少一个“)”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.