Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Connect with Oracle 8i Database error: java.lang.ArrayIndexOutOfBoundsException: 4

eaa46500-312f-4b71-b04d-8e463cf1035fDec 25 2017 — edited Dec 25 2017

I want to connect to Oracle 8i Database with java, where the database is on server on local network 10.3.1.1 at port

I have followed the example tutorial to make the connection from Oracle website

https://docs.oracle.com/html/A67296_01/im_examp.htm#997347

also I followed the instruction that specified here

https://people.cs.pitt.edu/~chang/156/06oracle/jdbc.html

You may need these details :

  • Oracle 8i Database port 1521
  • Local Network Server Running on Windows Server 2003 ip 10.3.1.1
  • java version "1.8.0_152" on machine on IP 10.3.1.2
  • added classes12.zip file to build path

This my Java Code:

  package com.oracle8i.testconnect;

  

  import java.sql.Connection;

  import java.sql.DriverManager;

  public class DBConnect {

    public Connection connection;

  

    public DBConnect(

          // TODO Auto-generated constructor stub

    }

  

    public void connect() throws Exception {

         String connectString;

         Class.forName("oracle.jdbc.driver.OracleDriver");

         connectString = "jdbc:oracle:thin:@10.3.1.1:1521:dbname";

         System.out.println("Before DriverManager.getConnection");

         try {

              connection = DriverManager.getConnection(connectString, "username", "password");

              System.out.println("Connection established");

  

              connection.setAutoCommit(false);

          } catch (Exception e) {

              // TODO: handle exception

              System.out.println("Exception inside connect(): " + e);

              e.printStackTrace();

         }  

    }

  

    public static void main(String[] args) {

         // TODO Auto-generated method stub

         DBConnect client = new DBConnect();

  

         System.out.println("beginning");

         try {

              client.connect();

              System.out.println("after Connected");

  

              client.connection.close();

  

              System.out.println("after close");

  

         } catch (Exception e) {

              // TODO: handle exception

              try {

                   System.out.println("Exception : " + e);

                   client.connection.close();

                   e.printStackTrace();

              } catch (Exception ex) {

              // TODO: handle exception

                   System.out.println("Close Connection Exception : " + ex);

                   ex.printStackTrace();

              }

         }

  

     }

}

I get this error message:

    beginning

    Before DriverManager.getConnection

    Exception inside connect(): java.lang.ArrayIndexOutOfBoundsException: 4

    java.lang.ArrayIndexOutOfBoundsException: 4

    at oracle.jdbc.driver.T4C8TTIdty.<init>(T4C8TTIdty.java:491)

    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1434)

    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)

    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:711)

    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)

    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)

    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:558)

    at java.sql.DriverManager.getConnection(Unknown Source)

    at java.sql.DriverManager.getConnection(Unknown Source)

    at com.oracle8i.testconnect.DBConnect.connect(DBConnect.java:19)

    at com.oracle8i.testconnect.DBConnect.main(DBConnect.java:37)

    after Connected

    Exception : java.lang.NullPointerException

    Close Connection Exception : java.lang.NullPointerException

    java.lang.NullPointerException

    at com.oracle8i.testconnect.DBConnect.main(DBConnect.java:48)

----------------------------------------

I have looked on internet for solutions but nothing is working with me

These are my testing  and results:

  • Testing with wrong database name(SID)

I have tested changing the dabase name (sid) with wrong name to check if its connected or not and thankfully it seems the connection to oracle almost correct because it response this error

    java.sql.SQLException: Listener refused the connection with the following error:

    ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

   

    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673)

    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:711)

    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)

    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)

    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:558)

    at java.sql.DriverManager.getConnection(Unknown Source)

    at java.sql.DriverManager.getConnection(Unknown Source)

    at com.oracle8i.testconnect.DBConnect.connect(DBConnect.java:19)

    at com.oracle8i.testconnect.DBConnect.main(DBConnect.java:37)

    Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:

    ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

   

    at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:272)

    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:263)

    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)

    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)

    ... 8 more

  • Checking The database Listener

I've checked with the administrator the listener status and it is running (the system is running)

eupZu.jpg

  • Disable Firewall

I have Disabled Firewall

XbTyH.png

innwS.png

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 22 2018
Added on Dec 25 2017
3 comments
1,549 views