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

51 lines
1.5 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 {
public 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;
}
}
public 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;
}
}
}