tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Blackburn" <>
Subject Re: ?java.lang.NullPointerException? with JDBC connection from InitialContext
Date Wed, 31 Dec 2008 02:47:06 GMT
Thanks for the quick response David.
Yes, I forgot to mention, I have connected to the DB using MySQL
client using the same credentials as defined in the realm.

Also keep in mind the JDBCRealm for folder access control work, so a
connection is possible. For some reason its the connection obtained
from the InitialContext that does not work from the linux host. Also,
the connection obtained by the InitialContext does work when running
the application from my local machines (connecting to either a locally
hosted DB or the linux hosted DB).

On Tue, Dec 30, 2008 at 9:30 PM, David Knox <> wrote:
> Hi Robert,
> Its not clear from your description if you've tried connecting to the database from the
linux box using the mysql client. MySQL security is host sensitive and you will need to grant
the user privileges to access the database from the linux host. Using the mysql client and
trying to connect to the remote database from the linux host, use the same credentials as
defined in your realm, will give you a clearer picture of what's going on. I suspect the NPE
is a symptom and the stacktrace in the catalina log is the source of the problem.
> --knoxy
> On Tuesday, December 30, 2008, at 07:15PM, "Robert Blackburn" <>
>>I am running Tomcat v6.0. I am developing and testing my app on my
>>local Windows machine, then publishing it to a Linux on the server
>>(not sure which distro). I have a real annoying issue, I've been
>>struggling with it for days.
>>I am using the same DB for my folder access control (JDBCRealm) as I
>>am from within the app itself. My problem is the folder access works
>>just fine, I am able to log in with credential from the DB. But I am
>>not able to use the connection from within the Java code itself. Every
>>connection attempt throws a "java.lang.NullPointerException". To make
>>it even more annoying, it works fine when running from my local
>>machine, its only on the Linux server that has trouble. So I know its
>>not a problem with the DB (I can even point my local machines to the
>>server's DB and it works just fine). The DB connection works, because
>>the JDBCRealm folder access control works, and the code work off my
>>I have this in the /conf/server.xml....
>>      <Realm className="org.apache.catalina.realm.JDBCRealm"
>>connectionName="username" connectionPassword="password"
>>driverName="com.mysql.jdbc.Driver" roleNameCol="roleNameCol"
>>userCredCol="userCredCol" userNameCol="userNameCol"
>>userRoleTable="userRoleTable" userTable="userTable"/>
>>And I put this in the /conf/Catalina/webapps/ROOT.xml ...
>>    <Resource name="jdbc/tranzzle" auth="Container"
>>type="javax.sql.DataSource"  username="username" password="password"
>>validationQuery="select 1"/>
>>(I've tried puting this in my /conf/context.xml too, hoping that would
>>help, but it didn't)
>>And this in my web.xml...
>>       <resource-ref>
>>               <res-ref-name>jdbc/tranzzle</res-ref-name>
>>               <res-type>javax.sql.DataSource</res-type>
>>               <res-auth>Container</res-auth>
>>       </resource-ref>
>>Here is the code I use to get the DB connection:
>>      // Obtain our environment naming context
>>      Context initCtx = new InitialContext();
>>      Context envCtx = (Context) initCtx.lookup("java:comp/env");
>>      // Look up our data source
>>      ds = (DataSource) envCtx.lookup("jdbc/tranzzle");
>>      Connection c = ds.getConnection();
>>Here is what I find in the error logs after I get this error...
>>   com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectQuotes(
>>   com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(
>>   com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(
>>   com.mysql.jdbc.CallableStatement.determineParameterTypes(
>>   com.mysql.jdbc.CallableStatement.<init>(
>>   com.mysql.jdbc.Connection.parseCallableStatement(
>>   com.mysql.jdbc.Connection.prepareCall(
>>   com.mysql.jdbc.Connection.prepareCall(
>>   org.apache.tomcat.dbcp.dbcp.DelegatingConnection.prepareCall(
>>   org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareCall(
>>And I also see this in the catalina.2008-12-30.log file:
>>   Dec 30, 2008 5:29:39 PM org.apache.catalina.realm.JDBCRealm getPassword
>>   SEVERE: Exception performing authentication
>>   com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException:
>>Communications link failure during commit(). Transaction resolution
>>       at com.mysql.jdbc.SQLError.createSQLException(
>>       at com.mysql.jdbc.Connection.commit(
>>       at org.apache.catalina.realm.JDBCRealm.getPassword(
>>       at org.apache.catalina.realm.JDBCRealm.authenticate(
>>       at org.apache.catalina.realm.JDBCRealm.authenticate(
>>       at org.apache.catalina.authenticator.FormAuthenticator.authenticate(
>>       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(
>>       at org.apache.catalina.core.StandardHostValve.invoke(
>>       at org.apache.catalina.valves.ErrorReportValve.invoke(
>>       at org.apache.catalina.core.StandardEngineValve.invoke(
>>       at org.apache.catalina.connector.CoyoteAdapter.service(
>>       at org.apache.jk.server.JkCoyoteHandler.invoke(
>>       at org.apache.jk.common.HandlerRequest.invoke(
>>       at org.apache.jk.common.ChannelSocket.invoke(
>>       at org.apache.jk.common.ChannelSocket.processConnection(
>>       at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(
>>       at org.apache.tomcat.util.threads.ThreadPool$
>>       at
>>Any help or suggestions would be appreciated
>>To unsubscribe, e-mail:
>>For additional commands, e-mail:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message