Charaf Eddine Mechalikh Charaf Eddine Mechalikh - 4 years ago 242
Java Question

Error when connecting via jdbc to Oracle 8i database using ojdbc6 driver

I want to connect to Oracle database via jdbc using ojdbc6 driver.

I have Oracle 10g in virtual machine, and Oracle 8i at work. I'm trying to create a java application that allows me to connect to the database and execute some SQL statement.

With Oracle 10g everything is fine,
but with oracle 8i (8.1.7) i get this error

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)


And this line of the stacktrace (jdbcon is my class name)

at jdbcon$4.actionPerformed(jdbcon.java:235)


Take me to this line of code

con=DriverManager.getConnection("jdbc:oracle:thin:@"+adresse+":"+port+":"+bd,user,pass);


The source code

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");


Note

when i use a wrong SID it gives me this error :

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


This means that the host,Port are okay. And when i use the right SID i get the previous error .

This problem is only with oracle 8i.

Answer Source

Oracle version 8 is not supported by ojdbc6 and ojdbc5 drivers (these are for later version of oracle) , to connect you need:

classes12.zip drivers that can be downloaded from Oracle8i JDBC Drivers

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download