JDBC连接Oracle11gR2的问题...急
我在家看马士兵老师的视频自学JDBC,看的过程中有几个问题请教,是关于JDBC连接数据库的问题。
1 我的JDK是1.6版本的
2 lomboz eclipse3.3的
3 Oracle 是11gR2
问题:
1 在马士兵老师的视频中,他用的数据库是oracle9i的,jdk是1.5的,他在添加驱动的时候是在oracle\ora90\jdbc\lib这个目录下添加的classes12.jar, 可是我在我11g的D:\Database\Oracle\product\11.2.0\dbhome_1\jdbc\lib目录下没有找到classes12.jar这个包,只有ojdbc5.jar,ojdbc6.jar这些包,是不是oracle版本升级了,用ojdbc6.jar和classes12.jar是一样的?
2 我在D:\Database\Oracle\product\11.2.0\dbhome_1\oui\jlib这个目录下找到了classes12.jar这个包,那么这个包和马老师的9i的oracle\ora90\jdbc\lib这个目录下classes12.jar是不是一样的啊?
3我把ojdbc6.jar这个包添加了进去,但是报错
错误如下:
Exception in thread "main"
java.sql.SQLException: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at TestJDBC.main(TestJDBC.java:7)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:359)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:672)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:237)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
... 7 more
Caused by:
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:141)
at oracle.net.nt.ConnOption.connect(ConnOption.java:123)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:337)
... 12 more
我写的代码如下:
import java.sql.*;
public class TestJDBC {
public static void main(String[] args) throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.100:1521:Monkey", "scott", "tiger");
}
}
4 我把ojdbc6.jar移除了之后又在程序中添加了classes12.jar这个包,但还是报错
代码还是上面的代码
错误如下图:
Exception in thread "main" java.sql.
SQLException: Io 异常: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:189)
at oracle.jdbc.dbacc