diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index f624cb6..f5267a1 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -2,8 +2,12 @@ package de.hsel.itech.db; import de.hsel.itech.config.Configuration; import org.jetbrains.annotations.Nullable; +import org.mariadb.jdbc.MariaDbPoolDataSource; -import java.sql.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; /** * @@ -14,16 +18,24 @@ import java.sql.*; */ public class Database { - public Database() { + private MariaDbPoolDataSource dataSource; + public Database() { + Configuration config = Configuration.get(); + dataSource = new MariaDbPoolDataSource("jdbc:mysql://" + config.getDatabase().getHostname() + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase()); + try { + dataSource.setUser(config.getDatabase().getUsername()); + dataSource.setPassword(config.getDatabase().getPassword()); + dataSource.initialize(); + } catch (SQLException e) { + e.printStackTrace(); + } } @Nullable private Connection getConnection() { - Configuration config = Configuration.get(); try { - return DriverManager.getConnection("jdbc:mariadb://" + config.getDatabase().getHostname() + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase(), config.getDatabase().getUsername(), config.getDatabase().getPassword()); - + return dataSource.getConnection(); } catch (SQLException e) { e.printStackTrace(); }