views:

259

answers:

2

I have some Java code that connects to an Oracle database using DriverManager.getConnection(). It works just fine on my Windows XP machine. However, when running the same code on a Solaris machine, I get the following exception. Both machines can reach the database machine on the network. I have included the Oracle trace logs.

Mar 23, 2010 12:12:33 PM org.apache.commons.configuration.ConfigurationUtils locate
FINE: ConfigurationUtils.locate(): base is /users/theUser/ADCompare, name is props.txt
Mar 23, 2010 12:12:33 PM org.apache.commons.configuration.ConfigurationUtils locate
FINE: Loading configuration from the path /users/theUser/ADCompare/props.txt
Mar 23, 2010 12:12:33 PM oracle.jdbc.driver.OracleDriver connect
FINE: OracleDriver.connect(url=jdbc:oracle:thin:@//theServer:1521/theService, info)
Mar 23, 2010 12:12:33 PM oracle.jdbc.driver.OracleDriver connect
FINER: OracleDriver.connect() walletLocation:(null)
Mar 23, 2010 12:12:33 PM oracle.jdbc.driver.OracleDriver parseUrl
FINER: OracleDriver.parseUrl(url=jdbc:oracle:thin:@//theServer:1521/theService)
Mar 23, 2010 12:12:33 PM oracle.jdbc.driver.OracleDriver parseUrl
FINER: sub_sub_index=12, end=46, next_colon_index=16, user=17, slash=18, at_sign=17
Mar 23, 2010 12:12:33 PM oracle.jdbc.driver.OracleDriver parseUrl
FINER: OracleDriver.parseUrl(url):return
Mar 23, 2010 12:12:33 PM oracle.jdbc.driver.OracleDriver connect
FINER: user=theUser, password=******, database=//theServer:1521/theService, protocol=thin, prefetch=null, batch=null, accumulate batch result =true, remarks=null, synonyms=null
Mar 23, 2010 12:12:33 PM oracle.jdbc.driver.PhysicalConnection <init>
FINE: PhysicalConnection.PhysicalConnection(ur="jdbc:oracle:thin:@//theServer:1521/theService", us="theUser", p="******", db="//theServer:1521/theService", info)
Mar 23, 2010 12:12:33 PM oracle.jdbc.driver.PhysicalConnection <init>
FINEST: PhysicalConnection.PhysicalConnection() : connectionProperties={user=theUser, password=******, protocol=thin}
Mar 23, 2010 12:12:33 PM oracle.jdbc.driver.PhysicalConnection initialize
FINE: PhysicalConnection.initialize(ur="jdbc:oracle:thin:@//theServer:1521/theService", us="theUser", access)
Mar 23, 2010 12:12:33 PM oracle.jdbc.driver.PhysicalConnection initialize
FINE: PhysicalConnection.initialize(ur, us):return
Mar 23, 2010 12:12:33 PM oracle.jdbc.driver.PhysicalConnection needLine
FINE: PhysicalConnection.needLine()--no return
java.lang.ArrayIndexOutOfBoundsException: 31
        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)

The above exception is also thrown if I use OracleDataSource instead of the generic DriverManager.getConnection().

Any ideas on why the behavior is different in the different environments?

+2  A: 

It looks like there's an error in TNSNAMES.ORA from the lines

java.lang.ArrayIndexOutOfBoundsException: 31
        at oracle.net.nl.NVTokens.parseTokens(Unknown Source)
        ...
        at oracle.net.resolver.TNSNamesNamingAdapter.loadFile(Unknown Source)

I'm not up on the oracle configuration from solaris, but assuming it's similar to the win version, maybe you have an issue with the formatting of this file. Can you connect through a sqlplus console from that box?

Steve B.
I'm not sure why the thin driver decides to load a tnsnames.ora file, but according to the stack trace, it's definitively choking on the content of a tnsnames.ora file.
jarnbjo
I didn't even consider that it might be trying to load the tnsnames.ora file and choking on it. I'm specifying the Oracle JDBC driver in my code, but it's still not clear why it's trying to load tnsnames.ora. I will explore this further. Thanks for the help.
lupefiasco
A: 

One thing I forgot to mention is that my application is built for Java6. The Oracle database is 10g, but for whatever reason, upgrading to the 11g version of the driver (i.e. ojdbc6_g.jar) fixed the problem.

lupefiasco