请帮助我。我在Oracle 11.2.0 g
上安装了Windows 7 (32 bit)
,我正在尝试将数据库与jdk 1.7
连接
我收到错误说
---exception
java.sql.SQLRecoverableException:IO Error: The Network Adapter could not establish the connection
ORACLE_HOME=E:\app\OraDhanya\product\11.2.0\dbhome_1
CLASSPATH=E:\app\OraDhanya\product\11.2.0\dbhome_1\jdbc\lib\*;C:\Program Files\Java\jdk1.7.0_03\bin
Path=E:\app\OraDhanya\product\11.2.0\dbhome_1\BIN;C:\Program Files\Java\jdk1.7.0_03\bin;
Global Database Name =orcldhamanoj.168.1.100
SID=orcldhaman
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
System.out.println("Connecting to Database");
Connection cn=DriverManager.getConnection("jdbc:oracle:thin:@orcldhamanoj:1521:orcldhaman","SCOTT","Tiger1");
System.out.println("Connected to Database");
Statement st=cn.createStatement();
st.executeUpdate("create table User(UserID number(3), UserName varchar2(20));");
System.out.println("Table Created");
st.close();
cn.close();
}
catch (SQLException e)
{
System.out.println("exception"+e);
}
答案 0 :(得分:1)
该错误与JDBC无关,它是一个低级错误,告诉您网络层无法连接到运行Oracle服务器的计算机。原因可能是多重的:
答案 1 :(得分:0)
在DriverManager.getConnection
方法中,确保指定运行Oracle的计算机的IP地址 - 如果是当前计算机,则指定localhost。
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcldhaman","SCOTT","Tiger1");
// ^^^^^^^^^ <-- Or this could be an IP address
答案 2 :(得分:0)
我建议以下可能导致此类错误: