42 lines
987 B
Java
42 lines
987 B
Java
package de.hsel.itech.db;
|
|
|
|
import de.hsel.itech.config.Configuration;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.DriverManager;
|
|
import java.sql.SQLException;
|
|
|
|
/**
|
|
* @author Johannes Theiner
|
|
* @version 0.1
|
|
* @since 0.1
|
|
*/
|
|
public class Database {
|
|
|
|
public Database() {
|
|
try {
|
|
Class.forName("com.mariadb.jdbc.Driver");
|
|
} catch (ClassNotFoundException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
@Nullable
|
|
private Connection getConnection() {
|
|
Configuration config = Configuration.get("config.json");
|
|
try {
|
|
return DriverManager.getConnection("jdbc:mariadb://" + config.getDatabase().getHostname() + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase(), config.getDatabase().getUsername(), config.getDatabase().getPassword());
|
|
|
|
} catch (SQLException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |