You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by John <lo...@borg.apana.org.au> on 2003/01/09 03:26:25 UTC

Repost: Can't connect to a running network-enabled mysql server on localhost

Since I didn't get a response the first time round, and I CAN'T believe
that nobody has ever run into this before, and I can't find what I'm
looking for in the FAQ or the archive, and the doc. for tomcat4 seems to
be pretty much non-existent, and the notes with mm.mysql don't help,
I'll ask again...

I'm running tomcat 4.0.3 on debian woody with apache and mysql on the
same box.  I can connect to mysql from another machine via tcp/ip on
port 3306, and from perl and php4 scripts.

When I try this code under tomcat, i get an error about 'can't find a
mysql server on port 3306'

%<-------------------------------------------------------
<HTML>
  <HEAD>
    <TITLE>JSP Test Code</TITLE>
  </HEAD>

  <BODY>

    <%@ page import="java.sql.*" %>

    <TABLE BORDER=1 WIDTH=75%>
      <TR>
        <TH>Last Name</TH>
        <TH>First Name</TH>
      </TR>

      <% 
      Connection conn = null;
      Statement  st   = null;
      ResultSet  rs   = null;

      try
      {
        Class.forName("org.gjt.mm.mysql.Driver").newInstance();
        conn =
DriverManager.getConnection("jdbc:mysql://localhost/cartapp?user=root");
      }
      catch(Exception ex)
      {
        out.println("Exception handler!");
        out.println(ex);
      }
      finally
      {
        if(rs!=null)rs.close();
        if(st!=null)st.close();
        if(conn!=null)conn.close();
      }
    %>

  </BODY>
</HTML>

%<--------------------------------------------------------------------

but equivalent code (below) works just fine with pure java...

%<--------------------------------------------------------------------

import java.sql.*;

class HelloWorldApp {
    public static void main(String[] args) throws java.sql.SQLException{
        Connection conn = null;
        Statement  st   = null;
        ResultSet  rs   = null;

        try
        {
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          conn =
DriverManager.getConnection("jdbc:mysql://localhost/cartapp?user=root");
          st   = conn.createStatement();
          rs   = st.executeQuery("select * from employees");

          while (rs.next()) {
            System.out.println(rs.getString("lname_txt"));
          }
        }
        catch (Exception ex)
        {
          ex.printStackTrace();
        }
        finally
        {
          if( rs   != null) rs.close();
          if( st   != null) st.close();
          if( conn != null) conn.close();
        }
        
        System.out.println("Hello World!"); // Display "Hello World!"
    }
}

%<--------------------------------------------------------------------

Has anyone had any similar issues, and can point me in the right
direction?

-- 
Regards,

John Breen

+---------------------------------------------------------+-------------+
|  aaaa   pppppp   aaaa   n nnnn   aaaa   ww   ww  aaaa   |            
|
|     aa   pp   p     aa   nn  nn     aa  ww   ww     aa  | John Breen 
|
|  aaaaa   pp   p aaaaaa   nn  nn aaaaaa  ww w ww  aaaaa  | Coordinator
|
| a   aa   ppppp  a   aa   nn  nn a   aa  ww w ww a   aa  | APANA, Inc.
|
|  aaaa a  pp      aaaa a nnn nnn  aaaa a  wwwww   aaaa a | WA Region  
|
|         pppp                                            |            
|
+---------------------------------------------------------+-------------+
                      email: locutus@borg.apana.org.au


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Repost: Can't connect to a running network-enabled mysql server on localhost

Posted by John <lo...@borg.apana.org.au>.
On Thu, 2003-01-09 at 11:58, Mark Eggers wrote:
 
> If memory serves my correctly, 4.0.3 was a problem
> child for a number of reasons.  Can you move up to
> 4.0.6 and see if that helps with the problem?
> 
> Sorry to be not of much help.  I was going to say
> check your host and user tables in mysql, but if you
> can connect with the same URL, then that's obviously
> not the problem.
> 

actually mark, you've been a great help.

debian stable (woody) includes tomcat 4.0.3
testing(sarge) includes 4.0.4
unstable (sid) includes 4.1.16

now, without going to unstable/testing status packages, which is an
undesirable thing to do, i have installed 4.1.18 from a tarball and
started it up, and everything goes fine.

thanks a bunch dude!


-- 
Regards,

John Breen

+---------------------------------------------------------+-------------+
|  aaaa   pppppp   aaaa   n nnnn   aaaa   ww   ww  aaaa   |            
|
|     aa   pp   p     aa   nn  nn     aa  ww   ww     aa  | John Breen 
|
|  aaaaa   pp   p aaaaaa   nn  nn aaaaaa  ww w ww  aaaaa  | Coordinator
|
| a   aa   ppppp  a   aa   nn  nn a   aa  ww w ww a   aa  | APANA, Inc.
|
|  aaaa a  pp      aaaa a nnn nnn  aaaa a  wwwww   aaaa a | WA Region  
|
|         pppp                                            |            
|
+---------------------------------------------------------+-------------+
                      email: locutus@borg.apana.org.au


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Repost: Can't connect to a running network-enabled mysql server on localhost

Posted by Mark Eggers <it...@yahoo.com>.
John,

I haven't seen this, but I'm running a more convoluted
setup.

jdk 1.4.1_01
tomcat 4.1.18
cocoon2-dev (from cvs)

all on a Win2K/Pro box.

I have been able to get connections to mysql and
xindice.  I haven't tried postgresql yet since I don't
have a database in that.  All databases are local.

If memory serves my correctly, 4.0.3 was a problem
child for a number of reasons.  Can you move up to
4.0.6 and see if that helps with the problem?

Sorry to be not of much help.  I was going to say
check your host and user tables in mysql, but if you
can connect with the same URL, then that's obviously
not the problem.

/mde/
just my two cents . . . .

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Repost: Can't connect to a running network-enabled mysql server on localhost

Posted by Paul Campbell <se...@halcyon.com>.
You might start mysql with --log and see if that gives more info.

At 10:26 AM 1/9/2003 +0800, you wrote:
>Since I didn't get a response the first time round, and I CAN'T believe
>that nobody has ever run into this before, and I can't find what I'm
>looking for in the FAQ or the archive, and the doc. for tomcat4 seems to
>be pretty much non-existent, and the notes with mm.mysql don't help,
>I'll ask again...
>
>I'm running tomcat 4.0.3 on debian woody with apache and mysql on the
>same box.  I can connect to mysql from another machine via tcp/ip on
>port 3306, and from perl and php4 scripts.
>
>When I try this code under tomcat, i get an error about 'can't find a
>mysql server on port 3306'
>
>%<-------------------------------------------------------
><%@ page import="java.sql.*" %> 
>Last Name First Name 
><% Connection conn = null; Statement st = null; ResultSet rs = null; try { Class.forName("org.gjt.mm.mysql.Driver").newInstance(); conn = DriverManager.getConnection("jdbc:mysql://localhost/cartapp?user=root"); } catch(Exception ex) { out.println("Exception handler!"); out.println(ex); } finally { if(rs!=null)rs.close(); if(st!=null)st.close(); if(conn!=null)conn.close(); } %> 
>%<--------------------------------------------------------------------
>
>but equivalent code (below) works just fine with pure java...
>
>%<--------------------------------------------------------------------
>
>import java.sql.*;
>
>class HelloWorldApp {
>    public static void main(String[] args) throws java.sql.SQLException{
>        Connection conn = null;
>        Statement  st   = null;
>        ResultSet  rs   = null;
>
>        try
>        {
>          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
>          conn =
>DriverManager.getConnection("jdbc:mysql://localhost/cartapp?user=root");
>          st   = conn.createStatement();
>          rs   = st.executeQuery("select * from employees");
>
>          while (rs.next()) {
>            System.out.println(rs.getString("lname_txt"));
>          }
>        }
>        catch (Exception ex)
>        {
>          ex.printStackTrace();
>        }
>        finally
>        {
>          if( rs   != null) rs.close();
>          if( st   != null) st.close();
>          if( conn != null) conn.close();
>        }
>        
>        System.out.println("Hello World!"); // Display "Hello World!"
>    }
>}
>
>%<--------------------------------------------------------------------
>
>Has anyone had any similar issues, and can point me in the right
>direction?
>
>-- 
>Regards,
>
>John Breen
>
>+---------------------------------------------------------+-------------+
>|  aaaa   pppppp   aaaa   n nnnn   aaaa   ww   ww  aaaa   |            
>|
>|     aa   pp   p     aa   nn  nn     aa  ww   ww     aa  | John Breen 
>|
>|  aaaaa   pp   p aaaaaa   nn  nn aaaaaa  ww w ww  aaaaa  | Coordinator
>|
>| a   aa   ppppp  a   aa   nn  nn a   aa  ww w ww a   aa  | APANA, Inc.
>|
>|  aaaa a  pp      aaaa a nnn nnn  aaaa a  wwwww   aaaa a | WA Region  
>|
>|         pppp                                            |            
>|
>+---------------------------------------------------------+-------------+
>                      email: locutus@borg.apana.org.au
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>