Home » Developer & Programmer » JDeveloper, Java & XML » Unable to connect to Oracle with JDBC (Oracle 12.2.0.1)
Unable to connect to Oracle with JDBC [message #682273] Wed, 14 October 2020 16:46 Go to next message
andrewah
Messages: 2
Registered: October 2020
Junior Member
Hi,

I'm executing a JUnit test from Gradle. It attempts to connect to Oracle. The test is being executed from a server running Red Hat 7.8 (Maipo).

The attempt to get a connection fails with a NullPointerException.

The code behind the test runs fine when pasted into a standalone Java application.

I've run it using the diagnostic version of Oracle's JDBC drivers and the output is here:

Oct 14, 2020 11:10:30 PM oracle.jdbc.driver.BlockSource$ThreadedCachingBlockSource$BlockReleaserListener <init>
    INFO: setCollectionUsageThreshold<PS Old Gen>(644559667)
    Oct 14, 2020 11:10:30 PM oracle.jdbc.driver.T4CConnection logon
    INFO: Connection.logon: oracle.jdbc.driver.T4CConnection@e26fa72
    Oct 14, 2020 11:10:30 PM oracle.jdbc.driver.T4CConnection logon
    INFO: Operating System Process Identifier (SPID): null
    Oct 14, 2020 11:10:30 PM oracle.jdbc.driver.T4CConnection logon
    INFO: DRCP Enabled: false
The only thing different in this output compared to when I run the code as a standalone application is the line mentioning the SPID. When I run it standalone, a SPID number is reported & when I don't it's null. I have no idea why it would be null.

If anyone does have any ideas please let me know!!!

Thanks,

Andrew.

NB. For reference, the code is here:

    public Connection getConnection () throws Exception
    {
        oracle.jdbc.OracleConnection conn = null;

        oracle.jdbc.pool.OracleDataSource oraDataSrc = new oracle.jdbc.pool.OracleDataSource ();

        oraDataSrc.setURL ( "jdbc:oracle:thin:@//thing-scan.xxx.net:1521/xxx" );

        LOG.info ( "The jdbc URL has been set = " + oraDataSrc.getURL() );

        oraDataSrc.setUser     ( "BOBBINS" );

        LOG.info ( "Username has been set to " + oraDataSrc.getUser () );

        oraDataSrc.setPassword ( "NONSENSE" );

        LOG.info ( "Password has been set ");

        conn = ( oracle.jdbc.OracleConnection ) oraDataSrc.getConnection();

        LOG.info ("did we get here?");

        return conn;
    }

Re: Unable to connect to Oracle with JDBC [message #682274 is a reply to message #682273] Wed, 14 October 2020 17:00 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
WELCOME & THANKS for a superior initial post

I don't really do JAVA but it appears to me posted Java code is flawed.

Take a look at content of URL below
http://www.orafaq.com/wiki/JDBC

I believe Oracle expects username & password in line below
>oraDataSrc.setURL ( "jdbc:oracle:thin:@//thing-scan.xxx.net:1521/xxx" );
Re: Unable to connect to Oracle with JDBC [message #682275 is a reply to message #682274] Thu, 15 October 2020 03:03 Go to previous message
andrewah
Messages: 2
Registered: October 2020
Junior Member
Hi Blackswan,

thanks for the prompt reply.

I eventually got to the bottom of this, and it turns out that the root cause is an Oracle defect.

I hadn't noticed the exception message: "Server is sending a non-null replay context but our replayModes=[]", which led to:

https://support.oracle.com/knowledge/Middleware/2539833_1.html

Even though the versions of Oracle mentioned on the knowledge base differ from those I'm using, the behaviour is identical.

Andrew.
Previous Topic: Looking for help. Deliverables in Word and XML
Next Topic: How do I stop xmlquery from changing encoding?
Goto Forum:
  


Current Time: Tue Dec 03 11:56:56 CST 2024