/**
* Datei einfügen
*/
public void insertFile(int jNodeLevel, int jParentId, int jUserLevel,
String jCreator, String jKeywordGerman, String jKeywordEnglish,
String jContentGerman, String jContentEnglish) {
String message1 = "SQLException in createLeaf. Die Fehlermeldung lautet: ";
String message2 = "BatchUpdateException in createLeaf. Die Fehlermeldung lautet: ";
String message3 = "FileNotFoundException in createLeaf. Die Fehlermeldung lautet: ";
FileInputStream fis1 = null, fis2 = null;
PreparedStatement st = null;
try {
File flg = new File(jContentGerman);
File fle = new File(jContentEnglish);
if (flg.exists() || fle.exists()) {
Statement s = connection.createStatement();
s
.addBatch("INSERT INTO structure_tbl (node_level, parent_id, datetime, user_level) VALUES ("
+ jNodeLevel
+ " + 1, "
+ jParentId
+ ", CURRENT TIMESTAMP, " + jUserLevel + ")");
s
.addBatch("INSERT INTO data_tbl (creator, keyword_german, keyword_english) VALUES ('"
+ jCreator
+ "', '"
+ jKeywordGerman
+ "', '"
+ jKeywordEnglish + "')");
s
.addBatch("INSERT INTO structure_data_tbl (node_id, data_id) VALUES ((SELECT MAX(data_id) FROM data_tbl), (SELECT MAX(node_id) FROM structure_tbl))");
updateCounts = s.executeBatch();
if (flg.exists()) {
fis1 = new FileInputStream(flg);
System.out.println(flg + " Länge: " + (int) flg.length());
st = connection
.prepareStatement("UPDATE data_tbl SET content_german = ? WHERE data_id = (SELECT MAX(data_id) FROM data_tbl)");
st.setBinaryStream(1, fis1, (int) flg.length());
st.executeUpdate();
}
System.out.println(flg.length()
+ " Bytes wurden erfolgreich gespeichert.");
if (fle.exists()) {
fis2 = new FileInputStream(fle);
System.out.println(fle + " Länge: " + (int) fle.length());
st = connection
.prepareStatement("UPDATE data_tbl SET content_english = ? WHERE data_id = (SELECT MAX(data_id) FROM data_tbl)");
st.setBinaryStream(1, fis2, (int) fle.length());
st.executeUpdate();
}
System.out.println(fle.length()
+ " Bytes wurden erfolgreich gespeichert.");
}
} catch (FileNotFoundException e) {
System.out.println(message3 + e.getMessage());
} catch (BatchUpdateException e) {
System.out.println(message2 + e.getMessage());
} catch (SQLException e) {
System.out.println(message1 + e.getMessage());
}
try {
if (null != st)
st.close();
} catch (Exception e) {
}
try {
if (null != fis1)
fis1.close();
} catch (Exception e) {
}
try {
if (null != fis2)
fis2.close();
} catch (Exception e) {
}
}