Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Location
    Cincinnati
    Posts
    4

    Unanswered: mySQL JDBC - Losing the Ability to Connect

    I am working on a Java Web Application project using JDeveloper while connecting to a mySQL database (3.23.52-nt). My application works fine up until the 30th connection. After the 30th, I receive the following error message:

    ===========================================
    (org.gjt.mm.mysql.Driver error message):
    Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.lang.NullPointerException)

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    (com.mysql.jdbc.Driver error message):
    Unable to connect to any hosts due to exception: java.lang.NullPointerException

    ===========================================

    I have created a diagnostic class to keep track of my connections with the intent of finding connections that are being left open. I've included the code below. According to this class, all connections being opened are being closed.

    All database connections are being opened as follows:

    conn = DatabaseDebug.getConnection("StaffLoginAction.find Staff()"); // The string is simply the name of the method

    And they are being closed such as this:

    finally {
    try { if (conn != null) DatabaseDebug.close(conn, "StaffLoginAction.findStaff()"); } catch (Throwable c) {}
    try { if (rec != null) rec.close(); rec = null; } catch (Throwable c) {}
    try { if (st != null) st.close(); st = null; } catch (Throwable c) {}
    }

    Any suggestions would be most helpful.

    Thanks,

    Ryan

    // DEBUG CLASS:

    public class DatabaseDebug implements AppConstants {
    private static HashSet connections = new HashSet();
    private static int totalConnections = 0;
    private static int openConnections = 0;

    public DatabaseDebug() {}

    public static Connection getConnection(String source) {
    InitialContext ctx = null;
    Connection conn = null;

    try {
    Class.forName(DRIVER);
    conn = DriverManager.getConnection(URL, USER, PASSWORD);
    if (conn != null) {
    connections.add(source);
    totalConnections++;
    openConnections++;
    }
    }
    catch (SQLException sqlEx) {
    System.out.println("A SQL Exception occurred while trying to establish the connection: " + sqlEx.getMessage());
    }
    catch (Exception e) {
    System.out.println("An Exception occurred in DatabaseDebug.getConnection: " + e.getMessage());
    }

    return conn;
    }

    public static void close(Connection conn, String source) {
    try {
    if (conn != null && !conn.isClosed()) {
    conn.close();
    connections.remove(source);
    openConnections--;
    }

    conn = null;
    }
    catch (SQLException ex) {
    System.out.println("There was an error closing the Connection(): " + ex.getMessage());
    }
    finally {
    Iterator elements = connections.iterator();

    System.out.println("============================== ===============");
    System.out.println(" OPEN CONNECTIONS: " + openConnections);

    while (elements.hasNext())
    System.out.println(" " + (String) elements.next());

    System.out.println(" TOTAL CONNECTIONS: " + totalConnections);
    System.out.println("============================== ===============\n\n");
    }
    }
    }

    STACK TRACE:

    03/10/26 01:40:49 A SQL Exception occurred while trying to establish the connection: Unable to connect to any hosts due to exception: java.lang.NullPointerException

    03/10/26 01:40:49 at com.evermind.server.http.ServletRequestDispatcher. forwardInternal(ServletRequestDispatcher.java:317)

    03/10/26 01:40:49 at com.evermind.server.http.HttpRequestHandler.proces sRequest(HttpRequestHandler.java:784)

    03/10/26 01:40:49 at com.evermind.server.http.HttpRequestHandler.run(Ht tpRequestHandler.java:270)

    03/10/26 01:40:49 at com.evermind.server.http.HttpRequestHandler.run(Ht tpRequestHandler.java:112)

    03/10/26 01:40:49 at com.evermind.util.ReleasableResourcePooledExecutor $MyWorker.run(ReleasableResourcePooledExecutor.jav a:192)

    03/10/26 01:40:49 at java.lang.Thread.run(Thread.java:536)

    03/10/26 01:40:49 java.sql.SQLException: Unable to connect to any hosts due to exception: java.lang.NullPointerException

    03/10/26 01:40:49 at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:1797)

    03/10/26 01:40:49 at com.mysql.jdbc.Connection.<init>(Connection.java:5 62)

    03/10/26 01:40:49 at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:361)

    03/10/26 01:40:49 at java.sql.DriverManager.getConnection(DriverManager .java:512)

    03/10/26 01:40:49 at java.sql.DriverManager.getConnection(DriverManager .java)

    03/10/26 01:40:49 at com.courseload.mainApp.DatabaseDebug.getConnection (DatabaseDebug.java:31)

    03/10/26 01:40:49 at com.courseload.mainApp.tags.OnOrderTag.doStartTag( OnOrderTag.java:40)

    03/10/26 01:40:49 at _staff._manage._jspService(manage.jsp:97)

    03/10/26 01:40:49 at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:13 9)

    03/10/26 01:40:49 at oracle.jsp.runtimev2.JspPageTable.service(JspPageT able.java:348)

    03/10/26 01:40:49 at oracle.jsp.runtimev2.JspServlet.internalService(Js pServlet.java:509)

    03/10/26 01:40:49 at oracle.jsp.runtimev2.JspServlet.service(JspServlet .java:413)

    03/10/26 01:40:49 at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)

    03/10/26 01:40:49 at com.evermind.server.http.ResourceFilterChain.doFil ter(ResourceFilterChain.java:65)

    03/10/26 01:40:49 at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZN Filter.java:356)

    03/10/26 01:40:49 at com.evermind.server.http.ServletRequestDispatcher. invoke(ServletRequestDispatcher.java:614)

    03/10/26 01:40:49 at com.evermind.server.http.ServletRequestDispatcher. forwardInternal(ServletRequestDispatcher.java:317)

    03/10/26 01:40:49 at com.evermind.server.http.ServletRequestDispatcher. forward(ServletRequestDispatcher.java:220)

    03/10/26 01:40:49 at com.evermind.server.http.EvermindPageContext.forwa rd(EvermindPageContext.java:223)

    03/10/26 01:40:49 at _controller._jspService(controller.jsp:20)

    03/10/26 01:40:49 at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:13 9)

    03/10/26 01:40:49 at oracle.jsp.runtimev2.JspPageTable.service(JspPageT able.java:348)

    03/10/26 01:40:49 at oracle.jsp.runtimev2.JspServlet.internalService(Js pServlet.java:509)

    03/10/26 01:40:49 at oracle.jsp.runtimev2.JspServlet.service(JspServlet .java:413)

    03/10/26 01:40:49 at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)

    03/10/26 01:40:49 at com.evermind.server.http.ResourceFilterChain.doFil ter(ResourceFilterChain.java:65)

    03/10/26 01:40:49 at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZN Filter.java:356)

    03/10/26 01:40:49 at com.evermind.server.http.ServletRequestDispatcher. invoke(ServletRequestDispatcher.java:614)

    03/10/26 01:40:49 An Exception occured in OnOrderTag(): null

    03/10/26 01:40:49 at com.evermind.server.http.ServletRequestDispatcher. forwardInternal(ServletRequestDispatcher.java:317)

    03/10/26 01:40:49 at com.evermind.server.http.HttpRequestHandler.proces sRequest(HttpRequestHandler.java:784)

    03/10/26 01:40:49 at com.evermind.server.http.HttpRequestHandler.run(Ht tpRequestHandler.java:270)

    03/10/26 01:40:49 at com.evermind.server.http.HttpRequestHandler.run(Ht tpRequestHandler.java:112)

    03/10/26 01:40:49 at com.evermind.util.ReleasableResourcePooledExecutor $MyWorker.run(ReleasableResourcePooledExecutor.jav a:192)

    03/10/26 01:40:49 at java.lang.Thread.run(Thread.java:536)
    Last edited by barg27; 10-26-03 at 23:56.

  2. #2
    Join Date
    Oct 2003
    Location
    Cincinnati
    Posts
    4

    Fixed It

    This appears to be an issue with JDeveloper. Once the application was ported over to Tomcat 4.1, it disappeared. Tomcat is set up with Connection Pooling, which may have also played a role in the fix.

  3. #3
    Join Date
    Jun 2004
    Posts
    2

    Angry MySQL/JDeveloper Solution?

    So is there no MySQL/JDeveloper solution for this problem???

  4. #4
    Join Date
    Oct 2003
    Location
    Cincinnati
    Posts
    4

    MySQL & JDeveloper

    My problem occurred in JDeveloper 9i. You may try 10g with it. I'm not sure if it would have the same problem. Check out this article on configuring JDevloper with mySQL (http://otn.oracle.com/products/jdev/...and_oc4j3.html).

    Unfortunately, the project I was working on isn't in a state in which I can fully test it with 10g so I can't prove it would work any better. However, configuration is likely where the problem is and that article spells it out rather nicely.

  5. #5
    Join Date
    Jun 2004
    Posts
    2

    Angry a

    Thanks barg27. I am using 10g. Also, I have read theMySQL how-to at Oracle. Everything seems to work until the crash...

  6. #6
    Join Date
    Oct 2003
    Location
    Cincinnati
    Posts
    4

    MySQL & JDeveloper

    Hopefully then, you're not using 0C4J for production. I'm not. I actually just like developing with JDeveloper. But my production environment was Tomcat. Therefore, I created a workaround. I created a DatabaseConnection object that had one method:

    public static Connection getConnection() {
    InitialContext ctx = null;
    Connection conn = null;

    try {
    ctx = new InitialContext();

    /**************************************
    ** PRODUCTION **
    **************************************/
    DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/courseload");
    conn = ds.getConnection();

    /**************************************
    ** DEVELOPMENT **
    **************************************/
    //Class.forName(DRIVER);
    //conn = DriverManager.getConnection(URL, USER, PASSWORD);
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    finally {
    try { if (ctx != null) ctx.close(); ctx = null; } catch (Throwable c) {}
    }

    return conn;
    }

    If you're not using the pool, then it seems to work with the DriverManager method. If you find a "real" solution, if you remember, please post it here. I'd be most interested in seeing what the root of the problem is.

Posting Permissions

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