这是我的方法
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);
}
}
我必须更改我的@localhost 部分
connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/xe", "STUDENT", "STUDENT");
使用一些东西,以便任何使用该程序的人都会收到高分列表。 我应该用什么来改变它?
最佳答案
在您的程序中,您只需将 localhost
更改为运行 Oracle 的计算机的 IP。
最大的工作是确保外部工作站可以到达该 IP 并且端口已打开。
所以你需要:
- 验证该 IP 是否可访问
- 验证端口是否打开
- 验证 oracle 的配置是否允许从外部 IP 加入。
关于连接到 SQL 的 Java 方法,我应该用什么更改 localhost 以便任何人都可以访问我的数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37811295/