Merge branch 'johannes2' of Studium/Internet-Technologien into master

This commit is contained in:
Johannes Theiner 2019-04-09 16:38:01 +00:00 committed by Gitea
commit e1e5299d2d

View File

@ -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();
}