12 Replies Latest reply: Mar 10, 2012 5:06 AM by rukbat RSS

    Runtime exception java.lang.ClassNotFoundException on executing Stored Proc

    904010

      I am getting the below error when I try to execute a stored proc in Pointbase from weblogic.

      java.sql.SQLException: The external "DbLog::insLog" routine had the following runtime exception "java.lang.ClassNotFoundException: DbLog"

      import java.sql.*; import com.pointbase.jdbc.*; public class DbLog { static Connection conn = null; static Statement m_stmt; static Statement l_stmt; static CallableStatement m_callStmt = null; public boolean logPreAuth() { try { String I_URL = "jdbc:pointbase:server://localhost:9093/weblogic_eval"; conn = DriverManager.getConnection(I_URL, "PBSYSADMIN", "PBSYSADMIN"); /*String SQL_CREATE_PROC = "CREATE PROCEDURE insLog(IN P1 VARCHAR(30))" + " LANGUAGE JAVA" + " SPECIFIC insLog" + " DETERMINISTIC" + " NO SQL" + " EXTERNAL NAME \"DbLog::insLog\"" + " PARAMETER STYLE SQL"; m_stmt = conn.createStatement(); m_stmt.executeUpdate(SQL_CREATE_PROC); m_stmt.close(); */ Commented out because it throwed error saying, The routine "INSLOG" in schema "PBPUBLIC" already exists in system table SYSROUTINES. m_callStmt = conn.prepareCall("{ call insLog(?) }"); m_callStmt.setString(1, "Success!!"); m_callStmt.execute(); } catch (Exception e) { logger.error("Error in logPreAuth method" + e); } return true; } public static void insLog(String test) { try { l_stmt = conn.createStatement(); l_stmt.executeUpdate("Insert into logs values('" + test + "')"); l_stmt.close(); conn.close(); } catch (Exception e) { } }

      Please let me know how to solve this.

        • 1. Re: Runtime exception java.lang.ClassNotFoundException on executing Stored Proc
          DrClap
          Same answer as what you got on the Java Ranch forum.
          • 2. Re: Runtime exception java.lang.ClassNotFoundException on executing Stored Proc
            904010
            I setted the classpath in commEnv.cmd as follows,
            set POINTBASE_HOME=%WL_HOME%\common\eval\pointbase
            set POINTBASE_CLIENT_CLASSPATH=%POINTBASE_HOME%\lib\pbclient57.jar
            set POINTBASE_CLASSPATH=%POINTBASE_HOME%\lib\pbembedded57.jar;%POINTBASE_CLIENT_CLASSPATH%;C:\bea\user_projects\workspaces\work1\utility\build\classes
            set POINTBASE_TOOLS=%POINTBASE_HOME%\lib\pbtools57.jar

            My DbLog class in the path, C:\bea\user_projects\workspaces\Work1\util\build\classes\net\local\util\common
            FYI, net\local\util\common is the package.

            But when I try to execute the page which calls RequestFilter.java, I am getting the following error,

            Error 500--Internal Server Error
            java.lang.NoClassDefFoundError: Could not initialize class net.local.util.common.DbLog

            Please find the code below,

            --RequestFilter.java
            import net.local.util.common.DbLog;   
              
            public final class RequestFilter {   
              
            public void log() {   
              
            DbLog dblog = new DbLog();   
            dblog.logPreAuth();   
            }   
            }  
            --DbLog.java
            package net.local.util.common;   
              
            import java.sql.*;   
            import org.apache.log4j.Logger;   
            import com.pointbase.jdbc.*;   
              
              
            public class DbLog {   
                   
                   
                private static final Logger logger = Logger.getLogger(DbLog.class);   
                private static boolean DEBUGGING = logger.isDebugEnabled();   
                private Connection conn = null;   
                private Statement m_stmt;   
                private Statement l_stmt;   
                private CallableStatement m_callStmt = null;   
                //static ResultSet l_rs = null;   
                   
                   
            public DbLog() {   
                   
                logger.info("DbLog constructor called");   
                init();   
                   
            }   
              
            public void init() {   
                logger.info("DbLog init called");   
            }   
              
              
                   
                   
            public void logPreAuth() {   
                           
                    try {   
                        logger.info("Inside logPreAuth method");   
                           
                           
                           
                        String I_URL = "jdbc:pointbase:server://localhost:9093/weblogic_eval";   
                        Class.forName("com.pointbase.jdbc.jdbcUniversalDriver").newInstance();   
                        //Class.forName("com.pointbase.jdbc.jdbcDataSource");   
                        conn = DriverManager.getConnection(I_URL, "PBPUBLIC", "PBPUBLIC");   
                           
                    String SQL_CREATE_PROC = "CREATE PROCEDURE insLog(IN P1 VARCHAR(30))"  
                            + " LANGUAGE JAVA"  
                            + " SPECIFIC insLog"  
                            + " DETERMINISTIC"  
                            + " NO SQL"  
                            + " EXTERNAL NAME \"DbLog::insLog\""  
                            + " PARAMETER STYLE SQL";    
              
              
                        m_stmt = conn.createStatement();   
                        m_stmt.executeUpdate(SQL_CREATE_PROC);   
                        m_stmt.close();     
                        m_callStmt = conn.prepareCall("{ call PBPUBLIC.insLog(?) }");   
                        m_callStmt.setString(1, "Success!!");   
                        m_callStmt.execute();    
                           
                    }   
                       
                       
                    catch (Exception e) {   
                        logger.error("Error in logPreAuth method" + e);   
                    }   
                   
                               
                }   
              
            public void insLog(String test)   
            {   
                try {   
                       
                    l_stmt = conn.createStatement();   
                    l_stmt.execute("Insert into logs values('" + test + "')");   
                    l_stmt.close();   
                    conn.close();   
                }   
                catch (Exception e) {   
                       
                }   
                   
            }   
                   
              
            }  
            • 3. Re: Runtime exception java.lang.ClassNotFoundException on executing Stored Proc
              jschellSomeoneStoleMyAlias
              Could not initialize class net.local.util.common.DbLog
              private static final Logger logger = Logger.getLogger(DbLog.class);
              private static boolean DEBUGGING = logger.isDebugEnabled();
              Those statements must work or class loading will fail.
              • 4. Re: Runtime exception java.lang.ClassNotFoundException on executing Stored Proc
                904010
                Well, when I set the classpath to "C:\bea\user_projects\workspaces\work1\utility\build\classes"
                And try to hit the page, I am getting

                java.lang.NoClassDefFoundError: org/apache/log4j/Logger
                ...
                Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
                ...

                And when I refresh the page,

                java.lang.NoClassDefFoundError: Could not initialize class net.verizon.whatsnext.util.common.DbLog


                But without setting the classpath to "C:\bea\user_projects\workspaces\work1\utility\build\classes", it was not showing this error and I was able to instantiate the DbLog object as I was able to output "DbLog constructor called" using logger

                But the problem there was, I couldn't call the stored procedure since it was throwing,
                java.sql.SQLException: The external "DbLog::insLog" routine had the following runtime exception "java.lang.ClassNotFoundException: DbLog"

                So before setting classpath, atleast it was going inside DbLog. Now its not at all going to DbLog class.
                Please suggest.
                • 5. Re: Runtime exception java.lang.ClassNotFoundException on executing Stored Proc
                  EJP
                  Well, when I set the classpath to "C:\bea\user_projects\workspaces\work1\utility\build\classes"
                  And try to hit the page, I am getting

                  java.lang.NoClassDefFoundError: org/apache/log4j/Logger
                  ...
                  Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
                  Exactly as expected. Does that directory contain that class? No. It is in a JAR file somewhere. So that JAR file must also be on the CLASSPATH. Same for probably a large number of other JARs.
                  • 6. Re: Runtime exception java.lang.ClassNotFoundException on executing Stored Proc
                    904010
                    No, I mean classpath had bunch of settings and I added that path "C:\bea\user_projects\workspaces\work1\utility\build\classes" to the end of it.

                    I removed it and now its going inside DbLog class and also creating the routine INSLOG(I found it is listed in Pointbase procedures list).
                    But its not able to execute it.
                    conn.prepareCall("{ call PBPUBLIC.insLog(?) }");
                    java.sql.SQLException: The external "DbLog::insLog" routine had the following runtime exception "java.lang.ClassNotFoundException: DbLog"

                    Please any suggestions? Struggling in this for past 2 days :(
                    • 7. Re: Runtime exception java.lang.ClassNotFoundException on executing Stored Proc
                      904010
                      I tried to create a simple class and executed from command prompt to make sure if its package problem, but still same problem occuring,

                      These are the steps I followed,

                      1) C:\bea\jrockit_160_05\bin>javac C:\bea\wlserver_10.3\common\eval\pointbase\lib\D
                      BLog.java

                      2) C:\bea\wlserver_10.3\common\eval\pointbase\lib>set classpath=C:\bea\wlserver_10.3\common\eval\pointbase\lib\pbclient57.jar

                      C:\bea\wlserver_10.3\common\eval\pointbase\lib>set classpath=%classpath%;C:\bea\
                      wlserver_10.3\common\eval\pointbase\lib

                      3) C:\bea\wlserver_10.3\common\eval\pointbase\lib>java DBLog

                      java.sql.SQLException: The external "DBLog::insLog" routine had the following ru
                      ntime exception "java.lang.ClassNotFoundException: DBLog"
                      at com.pointbase.net.netJDBCPrimitives.handleResponse(Unknown Source)
                      at com.pointbase.net.netJDBCPrimitives.handlePrimitiveResponse(Unknown S
                      ource)
                      at com.pointbase.net.netJDBCPreparedStatement.execute(Unknown Source)
                      at DBLog.main(DBLog.java:37)

                      This is the code --
                      import java.sql.*;
                      
                      public class DBLog {
                           
                           
                           private static Connection conn = null;
                           private static Statement m_stmt;
                           private static Statement l_stmt;
                           private static CallableStatement m_callStmt = null;
                           
                           
                      public static void main(String[] args)   
                      {   
                           try {
                                
                                String I_URL = "jdbc:pointbase:server://localhost:9093/weblogic_eval";
                                Class.forName("com.pointbase.jdbc.jdbcUniversalDriver");
                                
                                conn = DriverManager.getConnection(I_URL, "PBPUBLIC", "PBPUBLIC");
                                
                                String SQL_CREATE_PROC = "CREATE PROCEDURE insLog(IN P1 VARCHAR(30))"
                                     + " LANGUAGE JAVA"
                                     + " SPECIFIC insLog"
                                     + " DETERMINISTIC"
                                     + " NO SQL"
                                     + " EXTERNAL NAME \"DBLog::insLog\""
                                     + " PARAMETER STYLE SQL"; 
                      
                      
                                m_stmt = conn.createStatement();
                                m_stmt.executeUpdate(SQL_CREATE_PROC);
                                m_stmt.close();  
                                
                                m_callStmt = conn.prepareCall("{ call PBPUBLIC.insLog(?) }");
                                m_callStmt.setString(1, "Success!!");
                                m_callStmt.execute(); 
                                conn.close();
                                
                           }
                           
                           catch (Exception e) {
                                
                                e.printStackTrace();
                           }
                      
                           
                      }   
                      
                                
                                
                       
                      
                      public void insLog(String test)
                      {
                           try {
                                
                                l_stmt = conn.createStatement();
                                l_stmt.execute("Insert into logs values('" + test + "')");
                                l_stmt.close();
                               }
                           catch (Exception e) {
                                e.printStackTrace();
                           }
                           
                      }
                      
                      
                           
                      
                      }
                      Please suggest!
                      • 8. Re: Runtime exception java.lang.ClassNotFoundException on executing Stored Proc
                        Tolls
                        You're creating a procedure, 'insLog', that references;
                        EXTERNAL NAME \"DBLog::insLog\""

                        Now, I don't know Pointbase or how it works, but that there is your problem.
                        It is Pointbase raising this error, so no amount of classpath changes are likely to change how Pointbase looks for the class to execute...unless Pointbase uses the CLASSPATH environment set up in your particular terminal (very unlikely if you ask me).

                        Might I suggest checking up on the documentation around this syntax and see what should go in there or how to reference some external thing?
                        • 9. Re: Runtime exception java.lang.ClassNotFoundException on executing Stored Proc
                          904010
                          I read the pointbase documentation at, http://docs.oracle.com/cd/E19518-01/817-7464/817-7464.pdf

                          And it says,

                          In order for the database to access this external Java method, the class SampleExternalMethods
                          must be included in the database CLASSPATH. For PointBase Embedded - Server Option, it
                          must be in the Server CLASSPATH, but not in the Client CLASSPATH.

                          The java method can be static or non-static. If it is non-static, connection object will be
                          established during function invocation, so a non-static member variable of java.sql.connection
                          and a constructor having parameter java.sql.connection needs to be implemented. If it is static,
                          the method is called directly and no connection object will be established during function
                          invocation.

                          I setted the POINTBASE_CLASSPATH as mentioned in my previous posts but of no use. Did i miss anything?
                          Should I create a constructor with a connection parameter? But it says, if java method is static, then no connection object will be established during function invocation. Does this mean, no constructor with connection parameter is needed for static java method too?

                          Edited by: 901007 on 8 Mar, 2012 11:58 AM
                          • 11. Re: Runtime exception java.lang.ClassNotFoundException on executing Stored Proc
                            904010
                            plz any idea of my latest post here at http://www.coderanch.com/t/569413/JDBC/java/Runtime-exception-java-lang-ClassNotFoundException
                            Thanks
                            • 12. Re: Runtime exception java.lang.ClassNotFoundException on executing Stored Proc
                              rukbat
                              Moderator Action:
                              This thread is locked.
                              Since you cross-multi-posted, you don't seem to care about the assistance you might get here at OTN.
                              You can stay over there.