Added database initialisation
This commit is contained in:
@ -9,8 +9,10 @@ import java.util.List;
|
||||
public class Database {
|
||||
private Database() {
|
||||
try {
|
||||
if (!inited)
|
||||
throw new DatabaseException("Database not initialised");
|
||||
// TODO: Allow changing connection address
|
||||
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/skinner", "skinner", "skinner");
|
||||
connection = DriverManager.getConnection(address, username, password);
|
||||
|
||||
InputStream is = WebApp.class.getResourceAsStream("/sql/init.sql");
|
||||
executeScript(is);
|
||||
@ -51,6 +53,13 @@ public class Database {
|
||||
stmt.close();
|
||||
}
|
||||
|
||||
public static void init(String address, String username, String password) {
|
||||
Database.address = address;
|
||||
Database.username = username;
|
||||
Database.password = password;
|
||||
Database.inited = true;
|
||||
}
|
||||
|
||||
public static String[] getSkinHashes() throws SQLException {
|
||||
Statement stmt = getConnection().createStatement();
|
||||
ResultSet resultSet = stmt.executeQuery("SELECT _hash FROM skin;");
|
||||
@ -338,7 +347,11 @@ public class Database {
|
||||
private static Skin ensureDefaultSkin() throws SQLException {
|
||||
return ensureDefaultSkin(null);
|
||||
}
|
||||
|
||||
|
||||
private static boolean inited = false;
|
||||
private static String address;
|
||||
private static String username;
|
||||
private static String password;
|
||||
private boolean errored = false;
|
||||
private SQLException exception;
|
||||
private Connection connection;
|
||||
|
||||
@ -8,6 +8,9 @@ import com.sun.net.httpserver.*;
|
||||
public class WebApp {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// Initialise database
|
||||
Database.init("jdbc:mysql://localhost:3306/skinner", "skinner", "skinner");
|
||||
|
||||
// Create an HttpServer instance
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user