mardi 5 juillet 2016

Java method that connects to SQL , what should I change localhost with so anyone can access my database?

This is my method

 static void getHighScores() {
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException e) {

        System.out.println("Where is your Oracle JDBC Driver?");
        e.printStackTrace();
        return;
    }
    Connection connection = null;
    try {
        connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/xe", "STUDENT", "STUDENT");
    } catch (SQLException e) {
        System.out.println("Connection Failed! Check output console");
        e.printStackTrace();
        return;
    }
    try {
        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM HIGHSCORE ");
        System.out.println("Top Players");
        while (rs.next())
            System.out.println(rs.getString(1) + "  " + rs.getInt(2));
        connection.close();
    } catch (Exception e)

    {
        System.out.println(e);
    }
}

I have to change the @localhost part from my

 connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/xe", "STUDENT", "STUDENT");

With something so that anyone using the program would recive the list of HighScores. What should I change it with?

Aucun commentaire:

Enregistrer un commentaire