worked on dbcontroller part 2

fixed a few bugs but still a lot to do
This commit is contained in:
Seil0
2016-12-18 20:11:50 +01:00
parent 77f37955ae
commit a8e2f589ab
10 changed files with 74 additions and 81 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+33 -45
View File
@@ -1,7 +1,7 @@
/** /**
* DBController for Project HomeFlix * DBController for Project HomeFlix
* *
* TODO fav and defav * connection is in manual commit!
*/ */
package application; package application;
@@ -32,48 +32,35 @@ public class DBController {
private String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; // der Pfad der Datenbank-Datei private String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; // der Pfad der Datenbank-Datei
Connection connection = null; Connection connection = null;
public void main() public void main() {
{ try {
System.out.println("Hallo");
try
{
// create a database connection // create a database connection
connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH); connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH);
// Statement statement = connection.createStatement(); // Statement statement = connection.createStatement();
// statement.setQueryTimeout(30); // set timeout to 30 sec. TODO don't know wath to do with this // statement.setQueryTimeout(30); // set timeout to 30 sec. TODO don't know wath to do with this
connection.setAutoCommit(false); //Autocommit to false -> manual commit is active!
fuelleDatenbank(); fuelleDatenbank();
// ausgeben(); // ausgeben();
getFavStatus("House of Cards"); // getFavStatus("House of Cards");
favorisieren("House of Cards"); // favorisieren("House of Cards");
getFavStatus("House of Cards"); // getFavStatus("House of Cards");
defavorisieren("House of Cards"); // defavorisieren("House of Cards");
getFavStatus("House of Cards"); // getFavStatus("House of Cards");
} } catch (SQLException e) {
catch(SQLException e) // if the error message is "out of memory", it probably means no database file is found
{
// if the error message is "out of memory",
// it probably means no database file is found
System.err.println(e.getMessage()); System.err.println(e.getMessage());
} }
finally // finally {
{ // try {
try // if (connection != null)
{ // connection.close();
if(connection != null) // } catch (SQLException e) {
connection.close(); // // connection close failed.
} // System.err.println(e);
catch(SQLException e) // }
{ // }
// connection close failed.
System.err.println(e);
}
}
} }
public void fuelleDatenbank() { public void fuelleDatenbank() {
@@ -92,7 +79,6 @@ public class DBController {
PreparedStatement psS = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?)"); // SQL Befehl PreparedStatement psS = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?)"); // SQL Befehl
String[] entries = new File(mainWindowController.getPath()).list(); String[] entries = new File(mainWindowController.getPath()).list();
System.out.println("Size: "+entries.length);
for(int i=0;i!=entries.length;i++) // Geht alle Dateien im Verzeichniss durch for(int i=0;i!=entries.length;i++) // Geht alle Dateien im Verzeichniss durch
{ {
@@ -104,9 +90,7 @@ public class DBController {
} }
System.out.println("Erstelle Einträge streaming"); System.out.println("Erstelle Einträge streaming \n");
System.out.println(mainWindowController.getStreamingPath());
if(mainWindowController.getStreamingPath().equals("")||mainWindowController.getStreamingPath().equals(null)){ if(mainWindowController.getStreamingPath().equals("")||mainWindowController.getStreamingPath().equals(null)){
System.out.println("Kein Pfad angegeben"); //falls der Pfad null oder "" ist System.out.println("Kein Pfad angegeben"); //falls der Pfad null oder "" ist
}else{ }else{
@@ -131,16 +115,16 @@ public class DBController {
} }
} }
} }
connection.setAutoCommit(false); // connection.setAutoCommit(false);
ps.executeBatch(); // scheibt alle Einträge in die Datenbank ps.executeBatch(); // scheibt alle Einträge in die Datenbank
psS.executeBatch(); psS.executeBatch();
connection.setAutoCommit(true); connection.commit();
ps.close(); ps.close();
psS.close(); psS.close();
//connection.close(); //connection.close();
} catch (SQLException e) { } catch (SQLException ea) {
System.err.println("Konnte nicht ausgeführt werden"); System.err.println("Konnte nicht ausgeführt werden");
e.printStackTrace(); ea.printStackTrace();
} }
} }
@@ -200,8 +184,11 @@ public class DBController {
try{ try{
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
stmt.executeUpdate("UPDATE film_local SET rating=0 WHERE titel='"+name+"';"); stmt.executeUpdate("UPDATE film_local SET rating=0 WHERE titel='"+name+"';");
connection.commit(); //TODO hier kommt es zu fehlern mit dem autocommit connection.commit();
}catch(SQLException e){ }catch(SQLException e){
System.out.println("Ups! an error occured!");
e.printStackTrace();
}
try { try {
Statement stmtS = connection.createStatement(); Statement stmtS = connection.createStatement();
stmtS.executeUpdate("UPDATE film_streaming SET rating=0 WHERE titel='"+name+"';"); stmtS.executeUpdate("UPDATE film_streaming SET rating=0 WHERE titel='"+name+"';");
@@ -211,15 +198,17 @@ public class DBController {
e1.printStackTrace(); e1.printStackTrace();
} }
} }
}
//setzt die Favorisierung eines bestimmten Films //setzt die Favorisierung eines bestimmten Films
public void favorisieren(String name){ public void favorisieren(String name){
System.out.println("favorisieren ..."); System.out.println("favorisieren ...");
try{ try{
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
stmt.executeUpdate("UPDATE film_local SET rating=1 WHERE titel='"+name+"';"); stmt.executeUpdate("UPDATE film_local SET rating=1 WHERE titel='"+name+"';");
connection.commit(); //TODO hier kommt es zu fehlern mit dem autocommit connection.commit();
}catch(SQLException e){ }catch(SQLException e){
System.out.println("Ups! an error occured!");
e.printStackTrace();
}
try { try {
Statement stmtS = connection.createStatement(); Statement stmtS = connection.createStatement();
stmtS.executeUpdate("UPDATE film_streaming SET rating=1 WHERE titel='"+name+"';"); stmtS.executeUpdate("UPDATE film_streaming SET rating=1 WHERE titel='"+name+"';");
@@ -229,7 +218,6 @@ public class DBController {
e1.printStackTrace(); e1.printStackTrace();
} }
} }
}
//entfernt die Endung //entfernt die Endung
private String ohneEndung (String str) { private String ohneEndung (String str) {
+7 -2
View File
@@ -425,7 +425,12 @@ public class MainWindowController {
@FXML @FXML
private void debugBtnclicked(){ private void debugBtnclicked(){
dbController.main(); dbController.main(); //TODO das muss vor einen anderen Befehl warum auch immer
dbController.getFavStatus("House of Cards");
dbController.favorisieren("House of Cards");
dbController.getFavStatus("House of Cards");
// dbController.defavorisieren("House of Cards");
// dbController.getFavStatus("House of Cards");
//for testing //for testing
} }
@@ -514,7 +519,7 @@ public class MainWindowController {
System.out.println("Mode: "+mode); System.out.println("Mode: "+mode);
// dbController.ausgeben(); // dbController.main();
debugBtn.setDisable(false); //debugging btn for tests debugBtn.setDisable(false); //debugging btn for tests
debugBtn.setVisible(true); debugBtn.setVisible(true);
Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 B