Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

ClassNotFoundException COM.ibm.db2.jdbc.app.DB2Driver

$
0
0
I have one Web Project having onejava class which is connecting to DB2 datbase server and executing stroed procedure.

DB2 Client is installed locally on my desktop.
Java project having following external libraries in their classpath
db2java.zip,
db2jcc_license_cu.jar
db2jcc.jar

When it try to run locally with standlone application its working fine and returning resutl as per expectation, however when i deploy web application and trying to call from jsp page its giving me ClassNotFoundException excetpion.

code is as follows:

public class DB2Connection {

public static String DRIVER = "COM.ibm.db2.jdbc.app.DB2Driver";
public static String CONNECTIONSTRING = "jdbc:db2:mydatabase";
public static String USERID = "abcd";
public static String PASSWORD= "xxxx";
//connecting to DB2
public static Connection getDB2Connection() throws SQLException
{

Connection con = null;

try
{
//Load the driver
Class.forName(DRIVER);
System.out.println("DB2 driver loaded successfully.");

//Create connection using the IBM DB2 driver for JDBC
con = DriverManager.getConnection(CONNECTIONSTRING, USERID, PASSWORD);

if(con != null)
{
System.out.println("DB2 Database Connected Successfully.");
}else
{
System.out.println("DB2 Database Connection Failed!!!");
}//end if


}catch(ClassNotFoundException ex)
{
ex.printStackTrace();
System.out.println(" ClassNotFoundException " + ex.getMessage());

}catch(SQLException e)
{
e.printStackTrace();
System.out.println(" SQLException " + e.getMessage());
}

return con;

}//end getDB2Connection()
//Calling Stored Procedure
public int callDB2StoredProcedureWithOpenConnection(String param1, String param2) throws SQLException
{
CallableStatement cstmt = null;
Connection con = null;
int returnCode = 0;
String msg = null;

//opening connection to DB2
con = getDB2Connection();

//prepared statement to call DB2 stored procedure
cstmt = con.prepareCall("CALL schema-name.proc-name(?, ?, ?, ?)");

cstmt.setString(1,param1);
cstmt.setString(2, param2);

cstmt.registerOutParameter(3, Types.INTEGER);
cstmt.registerOutParameter(4, Types.VARCHAR);

//calling stroed procedure
cstmt.executeQuery();

returnCode = cstmt.getInt(3);
msg = cstmt.getString(4);

System.out.println(" code returned from stored procedure = " + returnCode);
System.out.println(" message returned from stored procedure = " + msg);

//closing database connection
con.close();

return returnCode;

}//end getDB2StoredProcedureWithOpenConnection()

//standalone call working fine and returnign result public static void main(String arg[]) throws Exception
{
DB2Connection db2con = new DB2Connection();
int returnCode = db2con.callDB2StoredProcedureWithOpenConnection("v alue1", "value2");
System.out.println(" Return Code : " + returnCode);

}//end main()
}//end class


jsp call to above class in Web App not working

<body>
Testing DB2 Connection on unixs913. <br>

<%
DB2Connection db2con = new DB2Connection();
int returnCode = 100;
returnCode = db2con.callDB2StoredProcedureWithOpenConnection("v alue1","value2");
%>

<br /> Return code from DB2 Stored Procedure Call is : <b><%= returnCode %></b>

</body>

any clue??

Viewing all articles
Browse latest Browse all 13329

Trending Articles