Solved

Getting ClassNotFoundException for external java method stored procedure in weblogic

Posted on 2012-03-11
10
515 Views
Last Modified: 2012-03-13
Please I need help in this desperately. Struggling with this NoClassDefFoundError :(

Created a portal web project (sampleWeb) with the following -

package net.local.util.common;

import java.sql.*;

import com.bea.netuix.transformer.openfoundation.util.XPSystem.Out;
import com.pointbase.jdbc.*;


public class DBLog {
	
	
	
	private Connection conn = null;
	private Statement m_stmt;
	private Statement l_stmt;
	private CallableStatement m_callStmt = null;
	
	
public DBLog() {
	
	Out.Write("DBLog constructor called");
	
}

	
	
public void logPreAuth() {
			
		try {
			Out.Write("Inside logPreAuth");
			
			
			
			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();  
			Out.Write("SP created");
			m_callStmt = conn.prepareCall("{ call PBPUBLIC.insLog(?) }");
			m_callStmt.setString(1, "Success!!");
			m_callStmt.execute(); 
			Out.Write("SP executed");
			
		}
		
		
		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();
		conn.close();
	}
	catch (Exception e) {
	e.printStackTrace();
		
	}
	
}
	

} 

Open in new window


And created a test.jsp with the following contents -

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    import="net.local.util.common.DBLog"
    %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>test</title>
</head>
<body>
<%
DBLog dblog = new DBLog();
dblog.logPreAuth();
 %>
</body>
</html>

Open in new window


Then added pbembedded57.jar into web projects "Add external Jar's Library" and built the project.

When I hit the page, http://localhost:7001/sampleWeb/faces/test.jsp

INFO: Initializing Mojarra (1.2_09-20081212-SNAPSHOT) for context '/sampleWeb'
DBLog constructor called
Inside logPreAuth
SP created
java.sql.SQLException: The external "DBLog::insLog" routine had the following runtime exception "java.lang.ClassNotFoundException: DBLog"
      at com.pointbase.net.netJDBCPrimitives.handleResponse(Unknown Source)
      at com.pointbase.net.netJDBCPrimitives.handlePrimitiveResponse(Unknown Source)
      at com.pointbase.net.netJDBCPreparedStatement.execute(Unknown Source)
      at net.local.util.common.DBLog.logPreAuth(DBLog.java:65)
                   ......

Also FYI, there were following 2 build warnings,
Classpath entry E:/Oracle/Middleware/wlserver_10.3/common/eval/pointbase/lib/pbembedded57.jar will not be exported or published. Runtime ClassNotFoundExceptions may result.        
The import com.pointbase.jdbc is never used      

Then tried adding "net.local.util.common.DBLog" to EXTERNAL NAME as follows,

 EXTERNAL NAME \"net.local.util.common.DBLog::insLog\"  but now I got the error,

DBLog constructor called
Inside logPreAuth
SP created
java.sql.SQLException: The external "net.local.util.common.DBLog::insLog" routine had the following runtime exception "java.lang.ClassNotFoundException: net.local.util.common.DBLog"
      at com.pointbase.net.netJDBCPrimitives.handleResponse(Unknown Source)
                   ......

Then I tried adding the following classpath entry to startPointbase.cmd,
@REM Add PointBase classes to the classpath
SET CLASSPATH=E:\Oracle\Middleware\user_projects\Workspaces\DBLog\sampleWeb\src\net\local\util\common;%POINTBASE_CLASSPATH%;%WEBLOGIC_CLASSPATH%

Now I got the error,

DBLog constructor called
Inside logPreAuth
SP created
java.sql.SQLException: The external "net.local.util.common.DBLog::insLog" routine had the following runtime exception "java.lang.ClassNotFoundException: net.local.util.common.DBLog"
      at com.pointbase.net.netJDBCPrimitives.handleResponse(Unknown Source)
                   ......

I also tried classpath "E:\Oracle\Middleware\user_projects\Workspaces\DBLog\sampleWeb\src" and again same above error.

Also tried adding external class folder in Libraries tab of Java build path. Still same above error.

I will be extremely thankful for any help.
0
Comment
Question by:weblogicme
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 37707871
Have you tried like that:

 EXTERNAL NAME 'net.local.util.common.DBLog.insLog'

I was also thinking that you need to have a static method to be able
to stotr in Java Stored Procedure

Another thing, I'd suggest to split these two tasks - make one piece of code which
would create java stored procedure - then you can check at the sql prompt if such
stored procedure was created and exists.

Then run a separate code which will have tested its operation
0
 

Author Comment

by:weblogicme
ID: 37708685
Tried like this,
EXTERNAL NAME \"net.local.util.common.DBLog.insLog\"

And got,
java.sql.SQLException: The routine name "null" does not contain a "::" to delimit the method name.

Tried like this,
EXTERNAL NAME \"net.local.util.common.DBLog.insLog::insLog\"

And got,
java.sql.SQLException: The external "net.local.util.common.DBLog.insLog::insLog" routine had the following runtime exception "java.lang.ClassNotFoundException: net.local.util.common.DBLog.insLog"

Tried like this,
EXTERNAL NAME \"net.local.util.common.DBLog::insLog\"

And got,
java.sql.SQLException: The external "net.local.util.common.DBLog::insLog" routine had the following runtime exception "java.lang.ClassNotFoundException: net.local.util.common.DBLog"

As you said, I changed my code and splitted it as follows,

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 static Connection conn = null;
	private static Statement m_stmt;
	private static Statement l_stmt;
	private static CallableStatement m_callStmt = 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.jdbcUniversalDriver");
		conn = DriverManager.getConnection(I_URL, "PBPUBLIC", "PBPUBLIC");
		
		doCreateProc();	
		doInvokeProc();
	}

	catch (Exception e) {
		logger.error("Error in logforSSP method" + e);
	}
	finally {
		if (m_stmt != null) {
			try {
				m_stmt.close();
			}
			catch (Exception e) {
				logger.info("Exception" + e);
			}
		}
		
		if (m_callStmt != null) {
			try {
				m_callStmt.close();
			}
			catch(Exception e) {
				logger.info("Exception: " + e);
			}
		}
		
		if (conn != null) {
			try {
				conn.close();
			}
			catch(Exception e) {
				logger.info("Exception :" + e);
			}
		}
	}

	}

public static void doCreateProc() throws SQLException {
	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();  
	logger.info("SP Created");
}

public static void doInvokeProc() throws SQLException 
{
		
		m_callStmt = conn.prepareCall("{ call PBPUBLIC.insLog(?) }");
		m_callStmt.setString(1, "Success!!");
		m_callStmt.executeUpdate(); 
				
		logger.info("SP executed");
		//l_rs = l_stmt.executeQuery("Insert into logs values('" + test + "')");
		//l_stmt.executeUpdate("Insert into logs values('" + test + "')");
		
		
	
}

public static void insLog(String test) {
	try {
		l_stmt = conn.createStatement();
		l_stmt.execute("Insert into logs values('" + test + "')");
		//l_rs.close();
		l_stmt.close();
	}
	catch(SQLException e){
		logger.info("SQL Exception: " + e);
	}
	finally {
		if (l_stmt != null) {
			try{
				l_stmt.close();
			}
			catch(Exception e) {
				logger.info("Exception: " + e);
			}
		}
	}
}

}

Open in new window


Still I got the error as,

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

And I can see from logs, till "SP Created" its going fine, and then after that its throwing error. Also checked in pointbase DB and found insLog routine is listed.
0
 

Author Comment

by:weblogicme
ID: 37709998
Its really strange. I followed the steps given in the below documentation on setting the classpath and still same error!

http://docs.oracle.com/cd/E19253-01/817-7465/817-7465.pdf

As they mentioned in that doc. under the section "Using JAR and ZIP files" in page 10, I updated pbembedded75.jar with DBLog.class package as follows,

jar -uf pbembedded57.jar net

In the above command, "net" is the folder package structure having DBLog.class inside it.

Verified whether commEnv.cmd is having right classpath and found the below,

set POINTBASE_CLASSPATH=C:\bea\user_projects\workspaces\WhatsNext\WhatsNextUtility\build\classes;%POINTBASE_HOME%\lib\pbembedded57.jar;%POINTBASE_CLIENT_CLASSPATH%

To make sure, I checked the console window while admin server is running, and it outputted the following,

echo CLASSPATH=;C:\bea\patch_wlw1030\profiles\default\sys_manifest_classpath\weblogic_patch.jar;C:\bea\patch_wls1030\profiles\default\sys_manifest_classpath\weblogic_patch.jar;C:\bea\patch_wlp1030\profiles\default\sys_manifest_classpath\weblogic_patch.jar;C:\bea\patch_cie670\profiles\default\sys_manifest_classpath\weblogic_patch.jar;C:\bea\JDK160~1\lib\tools.jar;C:\bea\WLSERV~1.3\server\lib\weblogic_sp.jar;C:\bea\WLSERV~1.3\server\lib\weblogic.jar;C:\bea\modules\features\weblogic.server.modules_10.3.0.0.jar;C:\bea\WLSERV~1.3\server\lib\webservices.jar;C:\bea\modules\ORGAPA~1.5/lib/ant-all.jar;C:\bea\modules\NETSFA~1.0_1/lib/ant-contrib.jar;;C:\bea\user_projects\workspaces\WhatsNext\WhatsNextUtility\build\classes;C:\bea\WLSERV~1.3\common\eval\pointbase\lib\pbembedded57.jar;C:\bea\WLSERV~1.3\common\eval\pointbase\lib\pbclient57.jar;C:\bea\WLSERV~1.3\server\lib\xqrl.jar;C:\bea\WLSERV~1.3\server\lib\xquery.jar;C:\bea\WLSERV~1.3\server\lib\binxml.jar;;

So pbembedded57.jar file is having DBLog.class and also my classpath is pointing to it.

Now I tried both the ways of calling EXTERNAL NAME \"DBLog::insLog\" as well as EXTERNAL NAME \"net.verizon.whatsnext.util.common.DBLog::insLog\" , and the result was the same error.
0
Three Considerations for Containers

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read our article on Experts Exchange.

 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 37712824
I was thinking that Pointbase is a demonstration database which comes with Weblogic for some testing and demonstration purposes. Is there any point of using such specific features as java stored procedures with this kind of database?
Doesn't it make more sense to install at least Oracle Express which is free and do any debugging with Oracle which has much better organized support for java stored procedures, and ability to load java stored procedure say using loadjava command.
In general, even with Oracle I'd think that application of java stored procedures is rather limited - in many cases it  makes more sense to use JDBC in conjunction with PL/SQL procedures, rather than java stored procedures even in Oracle. I would rather go away from Pointbase, and espcially of such features as java stored procedures in this kind of database.
0
 

Author Comment

by:weblogicme
ID: 37713431
I see. So does Oracle Express has a database in which I can create Stored procedures and call from java? The point is I need to test my local java code setup and see if I am able to make jdbc call to Oracle SP.
 So if Oracle Express has a database feature I can connect to, then I can very well try it.
Please suggest. Thanks
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37713504
As far as I know any Oracle supports Java stored procedure

And the way I tried was that I used lodjava command

In general I think you need to have a good reason to use Java Stored Procedure, don't see wvery manty cases where you would not be able to use JDBC + PL/SQL procedures instaed
0
 

Author Comment

by:weblogicme
ID: 37713767
Using oracle database client, is it possible to create a local test database, so that I can create stored procedures in it?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37713779
Yes, with Oracle Express you can create the oracke database right on your local machine and then you should be able to create your schem and load java stored proceduure in that schema.
0
 

Author Comment

by:weblogicme
ID: 37714146
No, I mean do I need to install database or client is sufficient? But I dont think I can create a database im my local system using client, right?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37716000
No, you need to download and instal Oracle Express database - this is of course not a client but quite separate product - it is the database which is limited in size and connections but otherwise it has Oracle database functionality and it is free.
And it makes much more sense than pointbase as everything you would develop with it is transferable to any oracle database.
0

Featured Post

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
Upgrading Tomcat – There are a couple of methods to upgrade Tomcat is to use The Apache Installer is to download and unzip and run the services.bat remove|install Tomcat6 Because of the App that we are working with, we can only use Tomcat 6.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question