0

Locally everything works fine, but on a remote Weblogic not really. The next code runs without any exception.

  try
    {
     ods = new OracleDataSource();
     connectionString = XmlReader.getConnectionString();
     ods.setURL(connectionString);
     }
    catch (SQLException ex)
    {
        ex.printStackTrace();
    }
    catch (Exception e) {
        e.printStackTrace();
    }

When i call getConnection() on the previous ods object, it doesnt raise any exception

 try
    {
        if (connection == null || connection.isClosed()) {
            connection = ods.getConnection();
        }
    }
    catch(Exception e) {
        e.printStackTrace();
    }

But finally the connection object is null for example after calling this

CallableStatement cstmt = connection.prepareCall( jobquery );

On a database it looks like the application created the connection, but then it doesnt call the procedure specified in "jobquery". What could be wrong?

Simply my question is: Is there a way to create an OracleDataSource without an exception, and then get a null from it?

1
  • Have you considered printing out the value of "connection" just after you obtain it, and again just before your connection.prepareCall(...) statement? This would help in seeing whether you get a real connection at all, and whether it is in place when you try to prepare the call. Commented Sep 20, 2012 at 14:08

2 Answers 2

1

Nambaris answer will probably solve your immediate issue. Other points to consider:

  1. On weblogic you really should be using built-in datasources and look those up by JNDI name
  2. Are you sure it doesn't throw an exception, or are you just not seeing it due to printing it out on stderr? You should be using logging mechanism and exception propagation, not printing to outputs.

These are not directly related to your problem, just things you should be doing in the long run.

Sign up to request clarification or add additional context in comments.

2 Comments

sorry but Nambaris answer is not related to my problem, i call executeQuery in my code. 1. Thanks for your advise, i will try it 2. I have a logging mechanism this was only an example
i created a datasource on weblogic and it works now. Thanks for your answer
1

Unless you miss some code in original question, it seems you didn't perform execute().

Example:

callableStatement.executeQuery();

Read this CallableStatement tutorial

3 Comments

Its not important, because the connection object is null, and the program fails at conn.prepareCall()
Ok, You are getting connection = ods.getConnection(); but you are using conn.prepareCall. Change it to connection .prepareCall and see
In my program its correct, I made a mistake only in this example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.