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 dkn...@mac.com 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
rwblackb...@gmail.com wrote:
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=trueamp;useUnicode=trueamp;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=trueamp;useUnicode=trueamp;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-namejdbc/tranzzle/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/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)