tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Abram Catalano" <ab...@adaptx.com>
Subject Connection Pooling/Jakarta prob/fix - Update or add to docs.
Date Thu, 12 Jun 2003 02:09:58 GMT
Referring to
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html

The example given for the JNDI MySQL connection pool had me stumped for a
time.  I did everything the example said, it wouldnt get past

if (ds != null) {  SEE BELOW for code

but would just finish the servlet (no execption thrown that I saw) when it
got to

Connection conn = ds.getConnection();

I had to lookup a different example, and realized from the exceptions
thrown, javauser@localhost.localdomain was being denied.

I changed  (in
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html)

mysql> GRANT ALL PRIVILEGES ON *.* TO javauser@localhost
    ->   IDENTIFIED BY 'javadude' WITH GRANT OPTION;

to

mysql> GRANT ALL PRIVILEGES ON *.* TO javauser@localhost.localdomain
    ->   IDENTIFIED BY 'javadude' WITH GRANT OPTION;

and all worked fine.

I am guessing thats just because locahost.localdomain is in the /etc/hosts
file??  RedHat 8.0
Keepers of the JNDI examples page my want to offer the note about localhost
stuff.

I would like an explanation for why I didn't see an error, I even tried to

try {
Connection conn = ds.getConnection();
}catch(SQLException se){
//println stuff
}

the servlet would appear to just end, nothing in the context's logs.

###################################################

To reiterate code:

package foo;

import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class DBTest {

  String foo = "Not Connected";
  int bar = -1;

  public void init() {
    try{
      Context ctx = new InitialContext();
      if(ctx == null )
          throw new Exception("Boom - No Context");

      DataSource ds =
            (DataSource)ctx.lookup(
               "java:comp/env/jdbc/TestDB");
//Look here

      if (ds != null) {
        Connection conn = ds.getConnection();

//end
        if(conn != null)  {
            foo = "Got Connection "+conn.toString();
            Statement stmt = conn.createStatement();
            ResultSet rst =
                stmt.executeQuery(
                  "select id, foo, bar from testdata");
            if(rst.next()) {
               foo=rst.getString(2);
               bar=rst.getInt(3);
            }
            conn.close();
        }
      }
    }catch(Exception e) {
      e.printStackTrace();
    }
 }

 public String getFoo() { return foo; }
 public int getBar() { return bar;}
}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message