Re: “java.lang.NullPointerException” with JDBC connection from InitialContext

2009-01-03 Thread Robert Blackburn
 Just some suggestions that come to mind:

 Have you considered googling for StringUtils indexOfIgnoreCaseRespectQuotes?
 E.g. it may be Connector/J bug #25047 fixed in v. 5.0.5
 Check, what version of MySQL Connector/J you are using.


OK, problem solved.
For the record I did search on that, and looked into it originally.
But stupidly, I verified that my test Connector/J was version v5.0.5
or later,... but must not have check the server. Sure enough the host
had v5.0.2. Upgrading the driver resolved this. Thank you Konstantin.

Thank you everyone who responded to my issue.

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



Re: “java.lang.NullPointerException” with JDBC connection from InitialContext

2008-12-31 Thread Konstantin Kolinko
2008/12/31 Robert Blackburn rwblackb...@gmail.com:
 (..)

 Any help or suggestions would be appreciated


Just some suggestions that come to mind:

Have you considered googling for StringUtils indexOfIgnoreCaseRespectQuotes?
E.g. it may be Connector/J bug #25047 fixed in v. 5.0.5
Check, what version of MySQL Connector/J you are using.

 com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4422)

The name suggests that the operation being performed is preparing some
sql Statement. Are you sure that it is getConnection() call that is
failing? Looks
like that succeeded, but some other call few lines later is failing.


Best regards,
Konstantin Kolinko

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



Re: ?java.lang.NullPointerException? with JDBC connection from InitialContext

2008-12-30 Thread Robert Blackburn
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)
  

RE: java.lang.NullPointerException with JDBC connection from InitialContext

2008-12-30 Thread Caldarale, Charles R
 From: Robert Blackburn [mailto:rwblackb...@gmail.com]
 Subject: java.lang.NullPointerException with JDBC
 connection from InitialContext

   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/

The above indicates the database for the realm is on localhost; is that true 
for both your test (Windows) system and the server (Linux) box?  Is localhost 
defined in the Linux box /etc/hosts file?

 And I put this in the /conf/Catalina/webapps/ROOT.xml ...

Unless you have a Host named webapps defined in server.xml, that doesn't do 
anything.  Also, any Resource would have to be nested inside a Context 
element, and you haven't indicated that's the case.

 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=trueamp;characterEncoding=UTF8
 validationQuery=select 1/

Again, this is using localhost; is that correct?  Are you using the same 
database for both application data and authentication/authorization?  (If so, 
that's a bit unusual.)

 (I've tried puting this in my /conf/context.xml too, hoping that would
 help, but it didn't)

That would make it available to all webapps, not just the one you're interested 
in.

Where did you put the jar containing the MySQL driver classes?  Make sure you 
don't have it in more than one place.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL and is thus for use only by the intended recipient. If you received 
this in error, please contact the sender and delete the e-mail and its 
attachments from all computers.

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