Ich versuche gerade via PreparedStatement einen Table zu erstellen, aber wenn ich das Programm laufen lasse wird kein Table erstellt...Ich habe das Query mal händisch per psql ausgeführt und da hat es funktioniert...
Hier ist die Klasse:
Hier ist die Klasse:
Java:
public class DatabaseConnector {
public static void main(String[] args) {
try (Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5435/aphbr", "aphbr", "7f960")) {
c.setAutoCommit(false);
System.out.println("Database Connection is established!");
//final DBActor person = new DBActor("Arnold", "Schwarzenegger");
int res = createTable(c);
System.out.println(res);
} catch (SQLException ex) {
System.out.println("Database Connection has failed!");
ex.printStackTrace();
}
}
private static int createTable(Connection c) throws SQLException {
PreparedStatement pre = c.prepareStatement("DROP TABLE IF EXISTS people; CREATE TABLE people (id NUMERIC PRIMARY KEY, first_name VARCHAR, last_name VARCHAR, persistent BOOL);");
System.out.println(pre.toString());
return pre.executeUpdate();
}
}