Core/src/main/java/eu/univento/core/api/server/ServerDatabase.java

69 lines
2.1 KiB
Java

package eu.univento.core.api.server;
import eu.univento.core.Core;
import eu.univento.core.api.database.MySQL;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author joethei
* @version 0.1
*/
public class ServerDatabase {
static String getIP(String name) {
MySQL sql = Core.returnSQL();
try {
sql.openConnection();
PreparedStatement st = sql.getConnection().prepareStatement("SELECT ip FROM Servers WHERE name='" + name + "'");
ResultSet rs = st.executeQuery();
if(rs.next()) {
String ip = rs.getString("ip");
sql.closeConnection();
return ip;
}
return null;
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
static int getPort(String name) {
MySQL sql = Core.returnSQL();
try {
sql.openConnection();
PreparedStatement st = sql.getConnection().prepareStatement("SELECT port FROM Servers WHERE name='" + name + "'");
ResultSet rs = st.executeQuery();
if(rs.next()) {
int port = rs.getInt("port");
sql.closeConnection();
return port;
}
return 0;
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
return 0;
}
}
static String getMotd(String name) {
MySQL sql = Core.returnSQL();
try {
sql.openConnection();
PreparedStatement st = sql.getConnection().prepareStatement("SELECT motd FROM Servers WHERE name='" + name + "'");
ResultSet rs = st.executeQuery();
if(rs.next()) {
String motd = rs.getString("motd");
sql.closeConnection();
return motd;
}
return null;
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
}