简体   繁体   中英

Database connection from weblogic

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?

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

Example:

callableStatement.executeQuery();

Read this CallableStatement tutorial

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM