import java.io.IOException;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PSQLConn {
public static void main(String[] args) throws InterruptedException, IOException, URISyntaxException, SQLException {
String database = "MyDatabase";
String dbUser = "myUser";
String dbPass = "mySecurePass";
String dbPort = "5432";
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://localhost:" + dbPort + "/" + database, dbUser, dbPass);
c.setAutoCommit(true);
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT \"ServerId\", \"ExternalAddress\", \"LocalIP\", \"GlobalIP\" FROM \"Servers\" WHERE \"Status\"=1;");
while(rs.next()) {
String serverId = rs.getString("ServerId");
String externalAddress = rs.getString("ExternalAddress");
String GlobalIP = rs.getString("GlobalIP");
String LocalIP = rs.getString("LocalIP");
//rs.getDate
//rs.getDouble
//rs.getBoolean
//rs.getInt
//rs.getFloat
//rs.getTime
//rs.getTimestamp
}
rs.close();
stmt.close();
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
}
c.close();
}
}