Archive

Archive for May, 2013

ArrayIndexOutOfBoundsException when creating a connection to an Oracle database

May 27, 2013 Leave a comment

More than once I encountered a java.lang.ArrayIndexOutOfBoundsException when creating a connection to an Oracle database using the SID of the database instead of the HOST:PORT:INSTANCE combination.

The stacktrace for this error usually looks like this:

java.lang.ArrayIndexOutOfBoundsException: <some number>
        at oracle.net.nl.NVTokens.parseTokens(Unknown Source)
        at oracle.net.nl.NVFactory.createNVPair(Unknown Source)
        at oracle.net.nl.NLParamParser.addNLPListElement(Unknown Source)
        at oracle.net.nl.NLParamParser.initializeNlpa(Unknown Source)
        at oracle.net.nl.NLParamParser.<init>(Unknown Source)
        at oracle.net.resolver.TNSNamesNamingAdapter.loadFile(Unknown Source)
        at oracle.net.resolver.TNSNamesNamingAdapter.checkAndReload(Unknown Source)
        at oracle.net.resolver.TNSNamesNamingAdapter.resolve(Unknown Source)
        at oracle.net.resolver.NameResolver.resolveName(Unknown Source)
        at oracle.net.resolver.AddrResolution.resolveAndExecute(Unknown Source)
        at oracle.net.ns.NSProtocol.establishConnection(Unknown Source)
        at oracle.net.ns.NSProtocol.connect(Unknown Source)
        at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1037)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:282)
        at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:468)
        at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:839)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:185)

It appears that Oracle’s java client has a bug – this exception occurs if the tnsnames.ora file has misplaced spaces/tabs/new-lines in particular places.

Oracle’s documentation states that the structure of a record in the tnsnames.ora file should be as such:

net_service_name= 
 (DESCRIPTION=
   (ADDRESS=...)
   (ADDRESS=...)
   (CONNECT_DATA=
    (SERVICE_NAME=sales.us.example.com)))

Definition such as the one below are illegal:

net_service_name= 
 (DESCRIPTION=
   (ADDRESS=...)
(ADDRESS=...)
   (CONNECT_DATA=
(SERVICE_NAME=sales.us.example.com)))

Apparently the indentation is crucial – if any of the lines in the block of a single net_service_name start at index 1 – this exception is thrown.
Only once you add indentation to all (can be spaces or tab) – it works. It doesn’t have to look good, but has to have an offset of some sort.

Important note – the only problem is with ‘(‘, indentation rules don’t apply to ‘)’.
E.g. the below example is perfectly fine:

net_service_name= 
     (DESCRIPTION=
       (ADDRESS=...
)
       (ADDRESS=...
)
       (CONNECT_DATA=
        (SERVICE_NAME=sales.us.example.com))
)

And here is the important excerpt from Oracle’s documentation:

Even if you do not choose to indent your files in this way, you must indent a wrapped line by at least one space, or it will be misread as a new parameter
The following layout is acceptable:

(ADDRESS=(COMMUNITY=tcpcom.world)(PROTOCOL=tcp)
   (HOST=max.world)(PORT=1521))

The following layout is not acceptable:

(ADDRESS=(COMMUNITY=tcpcom.world)(PROTOCOL=tcp)
(HOST=max.world)(PORT=1521))
Advertisements

Teaching Ditto to paste into SecureCRT

May 13, 2013 Leave a comment

I use Ditto and SecureCRT constantly on my day to day work, but by default – they don’t work well together.

Ditto supports being configured for specific applications to work in a different manner – all you need to do is to update the registry in the correct way.

How to do it?

Automatically

  1. Save the below into a file named Ditto_SecureCRT.reg
  2. Execute the file and choose Yes when prompted
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Ditto\PasteStrings]
"SecureCRT.exe"="+{INS}"

Manually

  1. Open the registry editor (Start -> Run -> regedit)
  2. Navigate to HKEY_CURRENT_USER\Software\Ditto
  3. If the Key PasteStrings does not exist, create it: Right-Click on Ditto -> New -> Key -> Name it as ‘PasteStrings’
  4. Add a new value for SecureCRT:
    1. Right-Click on PasteStrings -> New -> String Value -> Name it as ‘SecureCRT.exe’
    2. Double click on the new value, and give Value Data the value +{INS}

Either way you do it – the change is immediate, no need for a restart.

Categories: Tools Tags: , ,
%d bloggers like this: