Results 1 to 4 of 4
  1. #1
    hacktorious is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default MySQL, Netbeans 6.8 and Tomcat 6

    I'm having a difficult time getting my datasource to work in tomcat and netbeans. I have the mysql connector jar in the catalina_home/lib directory. When I right click the tomcat server in netbeans and look in the classes folder, the jar file is there. However, I continue to get a class not found exception. Below is the code, the log file output, and context file data. I'm all out of ideas, and have tried everything I could think of. Thanks.

    OH, I'm using Mac OSX SnowLeopard

    When I use the connection after calling it as follows I get the error:
    ConnectionPool pool = ConnectionPool.getInstance();
    Connection con = pool.getConection();

    *********** CLASS ***************
    package com.mindful.hcp.dao;

    import java.sql.Connection;
    import java.sql.SQLException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.sql.DataSource;
    import javax.naming.InitialContext;

    public class ConnectionPool {

    private static ConnectionPool pool = null;
    private static DataSource dataSource = null;

    private ConnectionPool() {
    try {
    InitialContext ic = new InitialContext();
    dataSource = (DataSource) ic.lookup("java:/comp/env/jdbc/hcp");
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    public static ConnectionPool getInstance() {
    if (pool == null) {
    pool = new ConnectionPool();
    }
    return pool;
    }

    public Connection getConection() {
    Connection connection = null;

    try {
    connection = dataSource.getConnection();
    } catch (SQLException ex) {
    Logger.getLogger(ConnectionPool.class.getName()).l og(Level.SEVERE, null, ex);
    }

    return connection;
    }

    public void freeConnection(Connection c) {
    try {
    c.close();
    } catch (SQLException ex) {
    Logger.getLogger(ConnectionPool.class.getName()).l og(Level.SEVERE, null, ex);
    }
    }
    }

    **************** TOMCAT LOG **************

    Jan 13, 2011 10:46:51 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet SessionServlet threw exception
    java.lang.NullPointerException
    at com.mindful.hcp.dao.SessionDao.scheduleNewSession( SessionDao.java:112)
    at com.mindful.hcp.services.SessionService.scheduleNe wSession(SessionService.java:28)
    at com.mindful.hcp.servlets.SessionServlet.processReq uest(SessionServlet.java:86)
    at com.mindful.hcp.servlets.SessionServlet.doPost(Ses sionServlet.java:251)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:680)


    ****************** TOMCAT OUTPUT CONSOLE *****************

    SEVERE: null
    org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.create DataSource(BasicDataSource.java:1136)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getCon nection(BasicDataSource.java:880)
    at com.mindful.hcp.dao.ConnectionPool.getConection(Co nnectionPool.java:40)
    at com.mindful.hcp.dao.SessionDao.scheduleNewSession( SessionDao.java:93)
    at com.mindful.hcp.services.SessionService.scheduleNe wSession(SessionService.java:28)
    at com.mindful.hcp.servlets.SessionServlet.processReq uest(SessionServlet.java:86)
    at com.mindful.hcp.servlets.SessionServlet.doPost(Ses sionServlet.java:251)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:680)
    Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at sun.misc.Launcher$ExtClassLoader.findClass(Launche r.java:229)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.create DataSource(BasicDataSource.java:1130)
    ... 20 more

    ****************** Context.xml ***********************

    <Resource name="jdbc/hcp" auth="Container"
    maxActive="100" maxIdle="30" maxWait="10000"
    username="dommer" password="test123"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/hcp?autoReconnect=true"
    logAbandoned="true" removeAbandoned="true"
    removeAbandonedTimeout="60" type="javax.sql.DataSource"/>
    Last edited by hacktorious; 01-14-2011 at 06:21 AM. Reason: added connection code

  2. #2
    hacktorious is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    Just figured out that if I try to do a single connection without a connection pool the code works fine. This proves that the driver is in the correct location. It must be an issue with the config.xml or something.

  3. #3
    hacktorious is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    Just tried this example: Apache Tomcat 6.0 - JNDI Datasource HOW-TO

    I get an error stating the driver cannot be loaded. This is very strange. The mysql drivers are correct and are in $CATALINA_HOME/lib
    Last edited by hacktorious; 01-16-2011 at 12:27 AM.

  4. #4
    hacktorious is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    Forget it. I was not able to get it to work after 3 days of messing with it. I decided to use C3P0 instead. Much better, it was up and running in about 10 minutes.

Similar Threads

  1. How to configure XAMPP Tomcat to Netbeans?
    By chyrl in forum Advanced Java
    Replies: 0
    Last Post: 11-10-2010, 01:22 PM
  2. Setting Up Tomcat 7.0 in Netbeans IDE 6.9
    By contributor in forum NetBeans
    Replies: 0
    Last Post: 08-27-2010, 07:19 AM
  3. NetBeans 6.8 , iReport and Tomcat 6.0.18
    By jeffreehy in forum NetBeans
    Replies: 4
    Last Post: 08-20-2010, 02:51 AM
  4. New to JSP-Netbeans, external tomcat server
    By dropez in forum JavaServer Pages (JSP) and JSTL
    Replies: 8
    Last Post: 04-01-2009, 07:48 PM
  5. MySql in NetBeans 5.0
    By javagal in forum NetBeans
    Replies: 6
    Last Post: 07-04-2007, 03:34 PM

Posting Permissions

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