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, [EMAIL PROTECTED] 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 [EMAIL PROTECTED] -> IDENTIFIED BY 'javadude' WITH GRANT OPTION; to mysql> GRANT ALL PRIVILEGES ON *.* TO [EMAIL PROTECTED] -> 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;} }