Commit bb980a0b authored by Oleh Astappiev's avatar Oleh Astappiev
Browse files

Read database credentials from properties file

parent bebffd5e
# IDEA
.idea
# Compiled files
target
# Database credentials
database.properties
......@@ -4,18 +4,17 @@ import de.l3s.shs.shsclienttest.test.Runner;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.io.InputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class DatabaseLogger {
private static final Logger logger = LogManager.getLogger(Runner.class);
private static final String databaseHost = "learnweb.l3s.uni-hannover.de:3306";
private static final String databaseName = "shs_evaluation";
private static final String databasePassword = "Ask Philipp, if you need";
public enum ProbeType {
shs,
redis,
......@@ -38,9 +37,22 @@ public class DatabaseLogger {
private String comment;
private PreparedStatement insertStatement;
private DatabaseManager databaseManager = new DatabaseManager(databaseHost, databaseName, databaseName, databasePassword);
private DatabaseManager databaseManager;
public DatabaseLogger(ProbeType probeType, String comment) throws SQLException {
try (InputStream input = DatabaseLogger.class.getClassLoader().getResourceAsStream("database.properties")) {
Properties prop = new Properties();
if (input == null) {
throw new IOException("Sorry, unable to find database.properties");
}
prop.load(input);
databaseManager = new DatabaseManager(prop.getProperty("database.host"), prop.getProperty("database.table"), prop.getProperty("database.username"), prop.getProperty("database.password"));
} catch (IOException ex) {
throw new RuntimeException("Can't read database credentials", ex);
}
databaseManager.getConnection().setAutoCommit(false);
insertStatement = databaseManager.prepareStatement("INSERT INTO request (probe_id, request_type, value, execution_time, results_count) VALUES (?, ?, ?, ?, ?);");
......
database.host = "localhost:3306";
database.table = "username";
database.username = "username";
database.password = "password";
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment