Results 1 to 4 of 4
  1. #1
    Join Date
    May 2013

    Unanswered: ClassNotFoundException

    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,

    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 = "";
    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;

    //Load the 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.");
    System.out.println("DB2 Database Connection Failed!!!");
    }//end if

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

    }catch(SQLException e)
    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(2, param2);

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

    //calling stroed procedure

    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

    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

    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>


    any clue??

  2. #2
    Join Date
    May 2013

    SQLException No suitable driver

    For, above code i have changed to db2java.jar and try running jsp page through web server, getting

    SQLException: NO Suitable driver.

  3. #3
    Join Date
    Apr 2008
    Iasi, Romania
    Provided Answers: 2
    You should post this on a Java forum - I don't think a DB2 DBA may help you.
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

  4. #4
    Join Date
    May 2013
    Thanks for your view, i guess thats right.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts