Merge branch 'johannes2' of Studium/Internet-Technologien into master
This commit is contained in:
commit
e1e5299d2d
|
@ -2,8 +2,12 @@ package de.hsel.itech.db;
|
||||||
|
|
||||||
import de.hsel.itech.config.Configuration;
|
import de.hsel.itech.config.Configuration;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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 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
|
@Nullable
|
||||||
private Connection getConnection() {
|
private Connection getConnection() {
|
||||||
Configuration config = Configuration.get();
|
|
||||||
try {
|
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) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue