tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Blackburn" <rwblackb...@gmail.com>
Subject “java.lang.NullPointerException” with JDBC connection from InitialContext
Date Wed, 31 Dec 2008 02:15:04 GMT
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
machine.

I have this in the /conf/server.xml....
      <Realm className="org.apache.catalina.realm.JDBCRealm"
connectionName="username" connectionPassword="password"
connectionURL="jdbc:mysql://localhost:3306/db_name?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF8"
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"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/db_name?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF8"
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...
java.lang.NullPointerException
   com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectQuotes(StringUtils.java:959)
   com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:
   com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3670)
   com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:
   com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:513)
   com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4422)
   com.mysql.jdbc.Connection.prepareCall(Connection.java:4496)
   com.mysql.jdbc.Connection.prepareCall(Connection.java:4470)
   org.apache.tomcat.dbcp.dbcp.DelegatingConnection.prepareCall(DelegatingConnection.java:275)
   org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareCall(PoolingDataSource.java:292)
I

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
unknown.
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:888)
	at com.mysql.jdbc.Connection.commit(Connection.java:2259)
	at org.apache.catalina.realm.JDBCRealm.getPassword(JDBCRealm.java:570)
	at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:401)
	at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:349)
	at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:258)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:417)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
	at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
	at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
	at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
	at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
	at java.lang.Thread.run(Thread.java:619)


Any help or suggestions would be appreciated

Thx

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message