我想使用 ojdbc6 驱动程序通过jdbc连接到Oracle数据库。
我在虚拟机中安装了Oracle 10g,而Oracle 8i正在运行。我试图创建一个允许我连接到数据库并执行一些SQL语句的java应用程序。
使用 Oracle 10g ,一切都正常, 但与 oracle 8i(8.1.7)我得到错误
java.lang.ArrayIndexOutOfBoundsException: 4
at oracle.jdbc.driver.T4C8TTIdty.<init>(T4C8TTIdty.java:488)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1199)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:340)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:553)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:254)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at jdbcon$4.actionPerformed(jdbcon.java:235)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6297)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
at java.awt.Component.processEvent(Component.java:6062)
at java.awt.Container.processEvent(Container.java:2039)
at java.awt.Component.dispatchEventImpl(Component.java:4660)
at java.awt.Container.dispatchEventImpl(Container.java:2097)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
at java.awt.Container.dispatchEventImpl(Container.java:2083)
at java.awt.Window.dispatchEventImpl(Window.java:2489)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:668)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:627)
at java.awt.EventQueue$2.run(EventQueue.java:625)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:641)
at java.awt.EventQueue$3.run(EventQueue.java:639)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:638)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
这一堆栈跟踪(jdbcon是我的类名)
at jdbcon$4.actionPerformed(jdbcon.java:235)
带我到这行代码
con=DriverManager.getConnection("jdbc:oracle:thin:@"+adresse+":"+port+":"+bd,user,pass);
源代码
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@"+adresse+":"+port+":"+bd,user,pass);
if(con.isValid(10))
//System.out.println("Connexion réussie");
JOptionPane.showMessageDialog(null, "Connexion réussie");
注意
当我使用错误的 SID 时,它会给我这个错误:
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
这意味着主机端口没问题。当我使用正确的SID 时,我得到了上一个错误。
此问题仅适用于 oracle 8i 。
答案 0 :(得分:2)
ojdbc6
和ojdbc5
驱动程序不支持Oracle版本8(这些版本适用于oracle的更高版本),您需要连接:
classes12.zip
个驱动程序
答案 1 :(得分:1)
你显然需要一个用于oracle8i的jdbc驱动程序,因为oracle10g和oracle8i不能使用相同的驱动程序