facebook

JDBC driver trouble. Please advise.

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #261354 Reply

    awebpro
    Member

    Here is a simple Struts action:

    //Created by MyEclipse Struts
    // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.4/xslt/JavaClass.xsl
    // Purpose: This action builds the first index page that is displayed
    // when the user types in the URL. This is the index or splash page.

    package com.gabble.struts.action;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;

    /**
    * MyEclipse Struts
    * Creation date: 11-04-2006
    *
    * XDoclet definition:
    * @struts:action validate=”true”
    */
    public class IndexPageAction extends Action {

    // ——————————————————— Instance Variables

    // ——————————————————— Methods

    /**
    * Method execute
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return ActionForward
    */
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) {

    Connection theConnection;
    System.out.println(“Makes it to step 1.”);
    try{

    //Loading driver
    Class.forName(“oracle.jdbc.OracleDriver”);
    System.out.println(“it is doing something.”);

    //Connect to emaildb Data source
    theConnection = DriverManager.getConnection(“jdbc:oracle:thin:@127.0.0.1:1521:orcl”, “user”, “passwd”);

    Statement theStatement=theConnection.createStatement();

    ResultSet theResult=theStatement.executeQuery(“select Name from dbtest.forums”);

    //Fetch all the records and print in table
    while(theResult.next()){
    System.out.println(“Name: ” + theResult.getString(1) + “</TD>”);
    }

    theResult.close();//Close the result set

    theStatement.close();//Close statement

    theConnection.close(); //Close database Connection

    } catch(Exception e){
    System.out.println(“it is not getting the driver.”);
    System.out.println(e.getMessage());//Print trapped error.

    }

    // if successfull, it forwards to the index page.
    ActionForward forward = null;
    forward = mapping.findForward(“indexSuccess”);

    // this action pulls data from the database and populates it in a bean.
    // that bean will be used in index.jsp to render the first page.

    return forward;

    }

    }

    Here is the console output:
    Makes it to step 1.
    it is not getting the driver.
    oracle.jdbc.OracleDriver

    So, obviously, it can’t find the driver. I have oraclehome/…/ojdbc14.jar in the classpath and in the lib subfolder. What am I missing? Please advise. Thanks. Could someone break down the exact steps needed to hit the database?

    #261423 Reply

    Riyad Kalla
    Member

    Are you running your application server (Is it Tomcat?) from within MyEclipse, or externally from the command line?

    #261457 Reply

    awebpro
    Member

    Tomcat 5.5, Oracle 10g, MyEclipse.

    I am running from within MyEclipse.

    #261474 Reply

    Riyad Kalla
    Member

    When you need to is go to your Tomcat 5 settings under WIndow > Preferences > MyEclipse > Application Servers > Tomcat 5 > Paths, and click the first “Add” box and add the JDBC driver JAR files to your classpath there, then relaunch Tomcat. That should get rid of the class not found problem.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: JDBC driver trouble. Please advise.

You must be logged in to post in the forum log in