下面是我的代码。我想从Oracle连接到Employee表。
public static void main(String[] args) {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection connection = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
Statement statement = connection.createStatement();
ResultSet resultset = statement.executeQuery("select 'Connected' from dual");
resultset.next();
String s = resultset.getString(1);
System.out.println(s);
statement.close();
connection.close();
} catch (Exception e) {
System.out.println("The exception raised is:" + e);
}
}
我总是得到这样的错误:“异常引发is:java.sql.SQLException: Io异常:网络适配器无法建立连接”
我试着关掉防火墙,但没成功。有没有人可以帮我解决这个问题。
发布于 2018-06-20 03:20:22
你试过远程登录那个数据库吗?就像..。
Telnet localhost 1521
只是为了检查是否有到该端口的进程列表。
https://stackoverflow.com/questions/50935464
复制相似问题