Announcement Announcement Module
Collapse
No announcement yet.
NullPointerException in OracleLobHandler Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • NullPointerException in OracleLobHandler

    Basically, I have 2 servers, one that host the database and the datasource. The other host all the applications and stuffs.

    One of my application requires to make use of xmltype in oracle, which is why I'm using a OracleLobHandler. Read the link below for more info.
    http://forum.springframework.org/showthread.php?t=29875

    The issue here is when my app server retrieve the datasource and tries to do it stuff, it encountered this error below.

    Code:
    Exception in thread "main" org.springframework.dao.DataAccessResourceFailureException:
    	Could not create Oracle LOB;
    		nested exception is org.springframework.dao.InvalidDataAccessApiUsageException:
    Couldn't initialize OracleLobHandler because Oracle driver classes are not available. Note that OracleLobHandler requires Oracle JDBC driver 9i or higher!; nested exception is java.lang.NullPointerException
    Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Couldn't initialize OracleLobHandler because Oracle driver classes are not available. Note that OracleLobHandler requires Oracle JDBC driver 9i or higher!; nested exception is java.lang.NullPointerException
    Caused by: java.lang.NullPointerException
    	at org.springframework.jdbc.support.lob.OracleLobHandler.initOracleDriverClasses(OracleLobHandler.java:150)
    	at org.springframework.jdbc.support.lob.OracleLobHandler$OracleLobCreator.createLob(OracleLobHandler.java:339)
    	at org.springframework.jdbc.support.lob.OracleLobHandler$OracleLobCreator.setClobAsString(OracleLobHandler.java:265)
    	at org.springframework.jdbc.core.support.SqlLobValue.setTypeValue(SqlLobValue.java:190)
    	at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:167)
    	at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:94)
    	at org.springframework.jdbc.core.ArgTypePreparedStatementSetter.setValues(ArgTypePreparedStatementSetter.java:68)
    	at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:742)
    	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:537)
    	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:738)
    	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:796)
    	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:800)
    However, if i put my application/modules onto my datasource/database server, it work perfectly.


    Does anyone have encountered it or have any idea on how to work about it???

  • #2
    I got a new clue on my problem. Hope it helps.

    It seem that the connection being came from here.

    Code:
    con = getOracleConnection(ps); Line 338 from OracleLobHandler.
    FYI, I'm using a SimpleNativeJdbcExtractor.

    Can anyone at spring explain why this is so??

    Comment


    • #3
      Well, I have found another issue where it point to NativeJdbcExtractorAdapter giving the problem.

      At line 108, it return back a null.

      Code:
      094     public Connection getNativeConnection(Connection con) throws SQLException {
      095         if (con == null) {
      096             return null;
      097         }
      098         Connection targetCon = DataSourceUtils.getTargetConnection(con);
      099         Connection nativeCon = doGetNativeConnection(targetCon);
      100         if (nativeCon == targetCon) {
      101             // We haven't received a different Connection, so we'll assume that there's
      102             // some additional proxying going on. Let's check whether we get something
      103             // different back from the DatabaseMetaData.getConnection() call.
      104             DatabaseMetaData metaData = targetCon.getMetaData();
      105             // The following check is only really there for mock Connections
      106             // which might not carry a DatabaseMetaData instance.
      107             if (metaData != null) {
      108                 Connection metaCon = metaData.getConnection();
      109                 if (metaCon != targetCon) {
      110                     // We've received a different Connection there:
      111                     // Let's retry the native extraction process with it.
      112                     nativeCon = doGetNativeConnection(metaCon);
      113                 }
      114             }
      115         }
      116         return nativeCon;
      117     }

      Comment


      • #4
        A couple of things to try:
        - Use WebLogicNativeJdbcExtractor. This may unwrap the connection better.
        - In your JndiTemplate don't set "java.naming.provider.url". Its possible that specifying the URL makes Weblogic create a remote DataSource object which would be impossible to unwrap. Excluding the URL guarantees Weblogic will connect locally.

        Comment


        • #5
          I already posted it on JIRA, stating it a bug. Got reply, and it will rectified in 2.0.9.

          Anyway, I think there another underlying issue for this.

          Apparently, OracleLobHandler need to work on a physical connection, rather than a stub/proxy. So if in my case where the datasource is retrieved from another server or another JVM, it a proxy/stub that is being passed over. Thus, it will lead to NotSerializableException.

          Comment


          • #6
            I've got a same problem

            I've got a same problem at the tomcat 5.5 and oracle 10g

            but I resolved...

            In my case, I put ojdbc14.jar into catalina_home/common/endored
            so The ojdbc14.jar was loaded by endored mechanism

            but in the endored mechanism we can't use classloader...

            import java.sql.*;
            public class TestConnection {

            public static void main(String args[]) throws Exception {
            String server = "192.168.123.243";
            String sid = "sid";
            String user = "oracle";
            String password = "oracle";

            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection c = DriverManager.getConnection("jdbc:oracle:thin:@123 .212.190.243:1521:ora10g", user, password);
            Class cl = c.getClass();
            ClassLoader clo = cl.getClassLoader();
            clo.loadClass("oracle.sql.BLOB");
            System.out.println("got connection : " +c);
            }
            }

            if you run this program like this.
            "java -cp ./ojdbc14.jar;.; TestConnection"
            in the above souce you can see following message
            "got connection : oracle.jdbc.driver.T4CConnection@7b7072"

            but if you run this program like this
            "java -Djava.endorsed.dirs=. TestConnection"
            You can see this message
            Exception in thread "main" java.lang.NullPointerException
            at TestConnection.main(TestConnection.java:16)

            so I removed ojdbc14.jar from endorse directory and put the library into the context/WEB-INF/lib

            Comment

            Working...
            X