I'm working on two tables. Table one is timeline and the second one is events. I want to delete all events when specific timeline is deleted but it's not working. Any suggestions?
Table Timeline:
public static void createtable(){
java.sql.Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:timeline_DB.db");
System.out.println("Opened database successfully");
stmt = c.createStatement();
String sql = "CREATE TABLE if not exists timeline_table " +
"(title VARCHAR(45) NOT NULL PRIMARY KEY , " +
" timeline_startdate INT(50) NOT NULL, " +
" timeline_startmonth INT(50) NOT NULL, " +
" timeline_enddate INT(50) NOT NULL, " +
" timeline_endmonth INT(50) NOT NULL, " +
" timeline_no INT(50) NOT NULL )";
String index1= "CREATE UNIQUE INDEX IF NOT EXISTS index_1 ON timeline_table (title)";
String index2 ="CREATE UNIQUE INDEX IF NOT EXISTS index_2 ON timeline_table (timeline_no)";
stmt.executeUpdate(sql);
stmt.executeUpdate(index1);
stmt.executeUpdate(index2);
stmt.close();
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
System.out.println("Timeline Table created successfully");
}
Table events:
public static void createEventtable(){
java.sql.Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:timeline_DB.db");
System.out.println("Opened database successfully");
stmt = c.createStatement();
String sql = "CREATE TABLE if not exists event_table " +
"(event_title VARCHAR(45) NOT NULL PRIMARY KEY , " +
" timeline_title VARCHAR(45) NOT NULL, " +
" event_startyear INT(50) NOT NULL, " +
" event_endyear INT(50) NOT NULL, " +
" event_startmonth INT(50) NOT NULL, " +
" event_endmonth INT(50) NULL, " +
" bar_length INT(50) NULL, " +
" x_bar INT(50) NULL, " +
" y_bar INT(50) NULL, " +
"event_des VARCHAR(45) NOT NULL ,"+
" FOREIGN KEY ('timeline_title') REFERENCES `timeline_table` (`title`) ON DELETE CASCADE ON UPDATE CASCADE)";
String index1= "CREATE INDEX IF NOT EXISTS index_1 ON timeline_table (event_title)";
stmt.executeUpdate(sql);
stmt.executeUpdate(index1);
stmt.close();
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
System.out.println("Event Table created successfully");
}
Aucun commentaire:
Enregistrer un commentaire