You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Steve Ryder <sr...@jsrsys.com> on 2010/01/25 06:32:40 UTC

Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

I am migrating from Tomcat 5.0 w/ MSQL 4.1 to Tomcat 5.5 w/ MySQL Server version: 5.0.51a-3ubuntu5 (Ubuntu). I have followed the Tomcat Tutorials changing 
from: ResourceLink in context.xml -> Resource in server.xml 
to: just Resource in context.xml. 

<Resource name="jdbc/MySql" auth="Container" type="javax.sql.Datasource" 
factory="org.apache.commons.dbcp.BasicDataSourceFactory" 
url="jdbc:mysql://localhost.localdomain/rsa?autoReconnect=true" 
driverClassName="com.mysql.jdbc.Driver" 
password="******" username="jsrsys" 
maxWait="10000" maxActive="200" maxIdle="5" 
removeAbandoned="true" removeAbandonedTimeout="300" logAbandoned="true" 
/> 
Note: password ****** not real password! 

My jdbc driver jar is: mysql-connector-java-5.0.8-bin.jar 
When my Java application tries to connect it throws the error: 
org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource 

The application code works fine with the old MySQL and Tomcat in both Fedora and Windows. I can't figure out what I may have done wrong or where to turn next. 

Any advice would be sincerely appreciated.

Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Steve Ryder <sr...@jsrsys.com>.
Some more testing... I added "displays" before each of the connect 
statements.  I get (still with no factory):
2010-01-25 16:27:07:*WARNING*Connection to jdbc/MySql:: connect Other 
exception: Cannot create resource instance
2010-01-25 16:27:07:JsrSQL: Context cast successfull
2010-01-25 16:27:07:Driver=com.mysql.jdbc.Driver
which tells me the failure is on the DataSource cast statement.

I then added factory back in and got:
2010-01-25 16:35:01:*WARNING*Connection to jdbc/MySql:: connect Other 
exception: org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource
2010-01-25 16:35:01:JsrSQL: Context cast successfull
2010-01-25 16:35:01:Driver=com.mysql.jdbc.Driver

So, failure is in same place with factory, but a different error.

I appreciate your suggestions, and look forward to other things I might need 
to change.

----- Original Message ----- 
From: "Caldarale, Charles R" <Ch...@unisys.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, January 25, 2010 8:52 AM
Subject: RE: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource


>> From: Steve Ryder [mailto:sryder@jsrsys.com]
>> Subject: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to
>> javax.sql.DataSource
>>
>> <Resource name="jdbc/MySql" auth="Container"
>> type="javax.sql.Datasource"
>> factory="org.apache.commons.dbcp.BasicDataSourceFactory"
>
> The specified factory is for the standard Apache commons DBCP, not the one 
> bundled with Tomcat.  You might try removing it and let the Tomcat DBCP 
> factory do its thing.
>
>> My jdbc driver jar is: mysql-connector-java-5.0.8-bin.jar
>
> Where is the JDBC jar located?
>
> Since you're upgrading, why not upgrade to 6.0.x?  (5.5 is not getting 
> much in the way of active development these days.)
>
> - 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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Steve Ryder <sr...@jsrsys.com>.
OK, I took factory out of context.xml, now I get Resource Instance again, 
but this time I have the trace!
2010-01-26 05:11:30:*WARNING*Connection to jdbc/MySql:: connect Other 
exception: Cannot create resource instance
2010-01-26 
05:11:30:Stack(10)=org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
2010-01-26 
05:11:30:Stack(9)=org.apache.jsp.AppList_jsp._jspService(AppList_jsp.java:157)
2010-01-26 05:11:30:Stack(8)=com.jsrsys.web.JsrSQL.(JsrSQL.java:42)
2010-01-26 
05:11:30:Stack(7)=com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86)
2010-01-26 05:11:30:Stack(6)=com.jsrsys.web.JsrSQL.connect(JsrSQL.java:504)
2010-01-26 
05:11:30:Stack(5)=org.apache.naming.NamingContext.lookup(NamingContext.java:153)
2010-01-26 
05:11:30:Stack(4)=org.apache.naming.NamingContext.lookup(NamingContext.java:781)
2010-01-26 
05:11:30:Stack(3)=org.apache.naming.NamingContext.lookup(NamingContext.java:140)
2010-01-26 
05:11:30:Stack(2)=org.apache.naming.NamingContext.lookup(NamingContext.java:793)
2010-01-26 
05:11:30:Stack(1)=javax.naming.spi.NamingManager.getObjectInstance(libgcj.so.81)
2010-01-26 
05:11:30:Stack(0)=org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
2010-01-26 05:11:30:JsrSQL: Context cast successfull

line 504 is the middle line of:
503 get's executed (see above):  sysout.display("JsrSQL: Context cast 
successfull");

504 throws exception:                 javax.sql.DataSource ds = 
(javax.sql.DataSource)envContext.lookup("jdbc/MySql");

505 never gets here:                  sysout.display("JsrSQL: DataSource 
cast successfull");


----- Original Message ----- 
From: "Christopher Schultz" <ch...@christopherschultz.net>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, January 25, 2010 2:40 PM
Subject: Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Steve,
>
> On 1/25/2010 2:56 PM, Steve Ryder wrote:
>> Starting from the bottom up of your suggestions:
>> 1)  I tried removing the try/catch.  No can do, Java compiler forces me
>> to catch the exceptions.
>
> Hmm... what method is declared as throwing "Exception" instead of
> something more specific?
>
>> 2)  However, Java does provide a getStackTrace.
>
> Throwable.printStackTrace() will also do the trick.
>
>> 2010-01-25
>> 19:37:09:Stack(5)javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>>
>> 2010-01-25
>> 19:37:09:Stack(4)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
>>
>> 2010-01-25
>> 19:37:09:Stack(3)org.apache.jsp.index_jsp._jspService(index_jsp.java:89)
>> 2010-01-25 19:37:09:Stack(2)com.jsrsys.web.JsrSQL.(JsrSQL.java:42)
>> 2010-01-25
>> 19:37:09:Stack(1)com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86)
>> 2010-01-25 
>> 19:37:09:Stack(0)com.jsrsys.web.JsrSQL.connect(JsrSQL.java:503)
>
> Is this the code you posted earlier? If so, which line is 503?
>
>> 2010-01-25 19:37:09:*WARNING*Connection to jdbc/MySql:: connect Other
>> exception: org.apache.naming.ResourceRef cannot be cast to
>> javax.sql.DataSource
>
> This isn't the error message you posted earlier. The one you posted
> earlier was:
>
> "
> 2010-01-25 15:56:06:*WARNING*Connection to jdbc/MySql:: connect Other
> exception: Cannot create resource instance
> "
>
>> Removing the Class.forName code did not change anything, I still get
>> the same error.
>
> Right: the Class.forName simply wasn't necessary... I didn't expect it
> to change anything.
>
>> 2010-01-25 20:00:03:*WARNING*Connection to jdbc/MySql:: connect Other 
>> exception: org.apache.naming.ResourceRef cannot be cast to 
>> javax.sql.DataSource
>>
>> 2010-01-25 
>> 20:00:03:Stack(4)=org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
>> 2010-01-25 
>> 20:00:03:Stack(3)=org.apache.jsp.index_jsp._jspService(index_jsp.java:89)
>> 2010-01-25 20:00:03:Stack(2)=com.jsrsys.web.JsrSQL.(JsrSQL.java:42)
>> 2010-01-25 
>> 20:00:03:Stack(1)=com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86)
>> 2010-01-25 
>> 20:00:03:Stack(0)=com.jsrsys.web.JsrSQL.connect(JsrSQL.java:504)
>> 2010-01-25 20:00:03:JsrSQL: Context cast successfull
>
> Could you re-post the whole method? The object you get from the JNDI
> context really /should/ be a javax.sql.DataSource object, not a
> ResourceLink.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkteAdMACgkQ9CaO5/Lv0PAm7wCfSWyuzVUbJ1zXqaruicFBoUnS
> R6wAn3JGjRZ7uMS5uf1tR8utZ7oWnzpT
> =ymR0
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org 


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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Steve Ryder <sr...@jsrsys.com>.
Sequence of events:
1)  With factory got cast error.
2)  Took out factory= and got "Cannot create resource instance"
3)  Put factory statement back in.  Is there a different one I should try?
The  cast exception is Thrown by this line
javax.sql.DataSource ds = 
(javax.sql.DataSource)envContext.lookup("jdbc/MySql");

in the connect method.   Here is the whole method as of the last test:

/**

* called by setDataBaseName

*/

private void connect(String dbName)

{

lastException = "OK";

/* don't need this if have connection pools

try

{

// Class.forName("org.gjt.mm.mysql.Driver");

sysout.display("Driver=com.mysql.jdbc.Driver");

Class.forName("com.mysql.jdbc.Driver");

}

catch (Exception E) {lastException=" Unable to load driver"; 
E.printStackTrace();

sysout.display(lastException);}

*/

try

{

sql = "Connection to jdbc/MySql:";

Context myContext = new InitialContext();

Context envContext = (Context)myContext.lookup("java:comp/env");

sysout.display("JsrSQL: Context cast successfull");

javax.sql.DataSource ds = 
(javax.sql.DataSource)envContext.lookup("jdbc/MySql");

sysout.display("JsrSQL: DataSource cast successfull");

conn = ds.getConnection();

sysout.display("JsrSQL: conn = ds successfull");

stmt = conn.createStatement();

sql = "USE "+ dbName; // attempt to mymic jdbcConnect set for dbName!

stmt.execute(sql);

sysout.display("**"+sql + ": connection to jdbc/MySql established.");

}

catch (SQLException E)

{ lastException="*WARNING*"+sql+ ": connect SQL exception: "

+ E.getMessage();

sysout.display(lastException);

}

catch(Exception eOther)

{

StackTraceElement[] stack = eOther.getStackTrace();

for (int s=0; s < stack.length; s++)

{

lastException = "Stack("+s+")=" + stack[s];

sysout.display(lastException);

if (lastException.indexOf("org.apache.jasper") > -1)

break;

}

lastException="*WARNING*"+sql+ ": connect Other exception: "

+ eOther.getMessage();

sysout.display(lastException);

}

}

----- Original Message ----- 
From: "Christopher Schultz" <ch...@christopherschultz.net>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, January 25, 2010 2:40 PM
Subject: Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Steve,
>
> On 1/25/2010 2:56 PM, Steve Ryder wrote:
>> Starting from the bottom up of your suggestions:
>> 1)  I tried removing the try/catch.  No can do, Java compiler forces me
>> to catch the exceptions.
>
> Hmm... what method is declared as throwing "Exception" instead of
> something more specific?
>
>> 2)  However, Java does provide a getStackTrace.
>
> Throwable.printStackTrace() will also do the trick.
>
>> 2010-01-25
>> 19:37:09:Stack(5)javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>>
>> 2010-01-25
>> 19:37:09:Stack(4)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
>>
>> 2010-01-25
>> 19:37:09:Stack(3)org.apache.jsp.index_jsp._jspService(index_jsp.java:89)
>> 2010-01-25 19:37:09:Stack(2)com.jsrsys.web.JsrSQL.(JsrSQL.java:42)
>> 2010-01-25
>> 19:37:09:Stack(1)com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86)
>> 2010-01-25 
>> 19:37:09:Stack(0)com.jsrsys.web.JsrSQL.connect(JsrSQL.java:503)
>
> Is this the code you posted earlier? If so, which line is 503?
>
>> 2010-01-25 19:37:09:*WARNING*Connection to jdbc/MySql:: connect Other
>> exception: org.apache.naming.ResourceRef cannot be cast to
>> javax.sql.DataSource
>
> This isn't the error message you posted earlier. The one you posted
> earlier was:
>
> "
> 2010-01-25 15:56:06:*WARNING*Connection to jdbc/MySql:: connect Other
> exception: Cannot create resource instance
> "
>
>> Removing the Class.forName code did not change anything, I still get
>> the same error.
>
> Right: the Class.forName simply wasn't necessary... I didn't expect it
> to change anything.
>
>> 2010-01-25 20:00:03:*WARNING*Connection to jdbc/MySql:: connect Other 
>> exception: org.apache.naming.ResourceRef cannot be cast to 
>> javax.sql.DataSource
>>
>> 2010-01-25 
>> 20:00:03:Stack(4)=org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
>> 2010-01-25 
>> 20:00:03:Stack(3)=org.apache.jsp.index_jsp._jspService(index_jsp.java:89)
>> 2010-01-25 20:00:03:Stack(2)=com.jsrsys.web.JsrSQL.(JsrSQL.java:42)
>> 2010-01-25 
>> 20:00:03:Stack(1)=com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86)
>> 2010-01-25 
>> 20:00:03:Stack(0)=com.jsrsys.web.JsrSQL.connect(JsrSQL.java:504)
>> 2010-01-25 20:00:03:JsrSQL: Context cast successfull
>
> Could you re-post the whole method? The object you get from the JNDI
> context really /should/ be a javax.sql.DataSource object, not a
> ResourceLink.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkteAdMACgkQ9CaO5/Lv0PAm7wCfSWyuzVUbJ1zXqaruicFBoUnS
> R6wAn3JGjRZ7uMS5uf1tR8utZ7oWnzpT
> =ymR0
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org 


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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steve,

On 1/25/2010 2:56 PM, Steve Ryder wrote:
> Starting from the bottom up of your suggestions:
> 1)  I tried removing the try/catch.  No can do, Java compiler forces me
> to catch the exceptions.

Hmm... what method is declared as throwing "Exception" instead of
something more specific?

> 2)  However, Java does provide a getStackTrace.

Throwable.printStackTrace() will also do the trick.

> 2010-01-25
> 19:37:09:Stack(5)javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> 
> 2010-01-25
> 19:37:09:Stack(4)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
> 
> 2010-01-25
> 19:37:09:Stack(3)org.apache.jsp.index_jsp._jspService(index_jsp.java:89)
> 2010-01-25 19:37:09:Stack(2)com.jsrsys.web.JsrSQL.(JsrSQL.java:42)
> 2010-01-25
> 19:37:09:Stack(1)com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86)
> 2010-01-25 19:37:09:Stack(0)com.jsrsys.web.JsrSQL.connect(JsrSQL.java:503)

Is this the code you posted earlier? If so, which line is 503?

> 2010-01-25 19:37:09:*WARNING*Connection to jdbc/MySql:: connect Other
> exception: org.apache.naming.ResourceRef cannot be cast to
> javax.sql.DataSource

This isn't the error message you posted earlier. The one you posted
earlier was:

"
2010-01-25 15:56:06:*WARNING*Connection to jdbc/MySql:: connect Other
exception: Cannot create resource instance
"

> Removing the Class.forName code did not change anything, I still get
> the same error.

Right: the Class.forName simply wasn't necessary... I didn't expect it
to change anything.

> 2010-01-25 20:00:03:*WARNING*Connection to jdbc/MySql:: connect Other exception: org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource
>
> 2010-01-25 20:00:03:Stack(4)=org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
> 2010-01-25 20:00:03:Stack(3)=org.apache.jsp.index_jsp._jspService(index_jsp.java:89)
> 2010-01-25 20:00:03:Stack(2)=com.jsrsys.web.JsrSQL.(JsrSQL.java:42)
> 2010-01-25 20:00:03:Stack(1)=com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86)
> 2010-01-25 20:00:03:Stack(0)=com.jsrsys.web.JsrSQL.connect(JsrSQL.java:504)
> 2010-01-25 20:00:03:JsrSQL: Context cast successfull

Could you re-post the whole method? The object you get from the JNDI
context really /should/ be a javax.sql.DataSource object, not a
ResourceLink.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkteAdMACgkQ9CaO5/Lv0PAm7wCfSWyuzVUbJ1zXqaruicFBoUnS
R6wAn3JGjRZ7uMS5uf1tR8utZ7oWnzpT
=ymR0
-----END PGP SIGNATURE-----

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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Steve Ryder <sr...@jsrsys.com>.
Starting from the bottom up of your suggestions:
1)  I tried removing the try/catch.  No can do, Java compiler forces me to 
catch the exceptions.
2)  However, Java does provide a getStackTrace.  There were 33 elements, but 
since pages that don't try to connect ARE working I think only the below 
apply:
2010-01-25 
19:37:09:Stack(5)javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
2010-01-25 
19:37:09:Stack(4)org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
2010-01-25 
19:37:09:Stack(3)org.apache.jsp.index_jsp._jspService(index_jsp.java:89)
2010-01-25 19:37:09:Stack(2)com.jsrsys.web.JsrSQL.(JsrSQL.java:42)
2010-01-25 
19:37:09:Stack(1)com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86)
2010-01-25 19:37:09:Stack(0)com.jsrsys.web.JsrSQL.connect(JsrSQL.java:503)
2010-01-25 19:37:09:*WARNING*Connection to jdbc/MySql:: connect Other 
exception: org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource
2010-01-25 19:37:09:JsrSQL: Context cast successfull
2010-01-25 19:37:09:Driver=com.mysql.jdbc.Driver
Not much help here, but it is very good to be able to print the trace when 
debugging so glad I was able to learn how.

I am now going to remove the Class.forName code and see if that changes any 
thing.
----- Original Message ----- 
From: "Christopher Schultz" <ch...@christopherschultz.net>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, January 25, 2010 12:07 PM
Subject: Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Steve,
>
> On 1/25/2010 11:16 AM, Steve Ryder wrote:
>> When I remove the factory line I now get:  Cannot create resource 
>> instance
>> 2010-01-25 15:56:06:*WARNING*Connection to jdbc/MySql:: connect Other
>> exception: Cannot create resource instance
>
> Ok.
>
>> The libraries are all in common\lib.  The ones I have added since the
>> 5.5 install are:
>> jsrweb (my Java code), mysql-connector-java-5.0.8-bin.jar,
>> naming-common.jar, naming-java.jar, mail.jar, and activation.jar.
>>
>> I picked 5.5 because it is not getting active develpment, yet supports
>> Java 1.5, and has all the features I need hoping to minimize
>> incompatabilities.
>
> Fair enough.
>
>> My Java "connect" code reads:   (indentation was lost when I copied)
>> private void connect(String dbName)
>> {
>> lastException = "OK";
>> try
>> {
>> // Class.forName("org.gjt.mm.mysql.Driver");  <---I changed this last
>> night hoping to fix problem.
>>
>> sysout.display("Driver=com.mysql.jdbc.Driver");
>>
>> Class.forName("com.mysql.jdbc.Driver");
>>
>> }
>> catch (Exception E) {lastException=" Unable to load driver";
>> E.printStackTrace();
>
> You don't need any of the above if you are using a connection pool: the
> pool will register the driver for you.
>
>> sysout.display(lastException);}
>
> What does this print, including the stack trace from the catch block?
>
>> try
>> {
>> sql = "Connection to jdbc/MySql:";
>> Context myContext = new InitialContext();
>> Context envContext = (Context)myContext.lookup("java:comp/env");
>
> Ok.
>
>> javax.sql.DataSource ds =
>> (javax.sql.DataSource)envContext.lookup("jdbc/MySql");
>>
>> conn = ds.getConnection();
>>
>> stmt = conn.createStatement();
>
> Ok.
>
>> sql = "USE "+ dbName; // attempt to mymic jdbcConnect set for dbName!
>>
>> stmt.execute(sql);
>
> This is not necessary as you have already selected your db via the
> connection URL.
>
>> catch (SQLException E)
>>
>> { lastException="*WARNING*"+sql+ ": connect SQL exception: "
>>
>> + E.getMessage();
>>
>> sysout.display(lastException);
>>
>> //System.exit(4);
>>
>> }
>> catch(Exception eOther)
>>
>> { lastException="*WARNING*"+sql+ ": connect Other exception: "
>>
>> + eOther.getMessage();
>>
>> sysout.display(lastException);
>>
>> //System.exit(4);
>>
>> }
>
> So, the above is the source of the error message which has all your
> extra stuff like "*WARNING*Connection to jdbc/MySql:: connect SQL
> exception:" plus the message from the real exception. I don't recognize
> "Cannot create resource instance" so it would be helpful to show the
> full stack trace and the real exception that caused the message to print.
>
> I would recommend not catching "Exception" unless there is a good reason
> to do so: allow the exception to propagate up the stack to a place where
> it can be appropriately caught and dealt with, or at least logged
> properly. What happens when this code fails and the "conn" member isn't
> set properly? I'm guessing you either get NullPointerExceptions later in
> your code, or you have to have a bunch of null checking in your query
> code which is kind of ugly.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEUEARECAAYFAktd3f0ACgkQ9CaO5/Lv0PD6CgCXWjgZIBoBQrgS7ciU7Y4L8TGt
> TQCbBC+bDwqmlEgAeiCXp/PdeweDFWM=
> =aaxM
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org 


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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Steve Ryder <sr...@jsrsys.com>.
Removing the Class.forName code did not change anything, I still get the 
same error.
2010-01-25 20:00:03:*WARNING*Connection to jdbc/MySql:: connect Other 
exception: org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource
2010-01-25 
20:00:03:Stack(4)=org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
2010-01-25 
20:00:03:Stack(3)=org.apache.jsp.index_jsp._jspService(index_jsp.java:89)
2010-01-25 20:00:03:Stack(2)=com.jsrsys.web.JsrSQL.(JsrSQL.java:42)
2010-01-25 
20:00:03:Stack(1)=com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86)
2010-01-25 20:00:03:Stack(0)=com.jsrsys.web.JsrSQL.connect(JsrSQL.java:504)
2010-01-25 20:00:03:JsrSQL: Context cast successfull

I have now changed my stack trace "display" code to stop when it hits the 
org.apache.jasper... code.
----- Original Message ----- 
From: "Christopher Schultz" <ch...@christopherschultz.net>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, January 25, 2010 12:07 PM
Subject: Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource



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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steve,

On 1/25/2010 11:16 AM, Steve Ryder wrote:
> When I remove the factory line I now get:  Cannot create resource instance
> 2010-01-25 15:56:06:*WARNING*Connection to jdbc/MySql:: connect Other
> exception: Cannot create resource instance

Ok.

> The libraries are all in common\lib.  The ones I have added since the
> 5.5 install are:
> jsrweb (my Java code), mysql-connector-java-5.0.8-bin.jar,
> naming-common.jar, naming-java.jar, mail.jar, and activation.jar.
> 
> I picked 5.5 because it is not getting active develpment, yet supports
> Java 1.5, and has all the features I need hoping to minimize
> incompatabilities.

Fair enough.

> My Java "connect" code reads:   (indentation was lost when I copied)
> private void connect(String dbName)
> {
> lastException = "OK";
> try
> {
> // Class.forName("org.gjt.mm.mysql.Driver");  <---I changed this last
> night hoping to fix problem.
> 
> sysout.display("Driver=com.mysql.jdbc.Driver");
> 
> Class.forName("com.mysql.jdbc.Driver");
> 
> }
> catch (Exception E) {lastException=" Unable to load driver";
> E.printStackTrace();

You don't need any of the above if you are using a connection pool: the
pool will register the driver for you.

> sysout.display(lastException);}

What does this print, including the stack trace from the catch block?

> try
> {
> sql = "Connection to jdbc/MySql:";
> Context myContext = new InitialContext();
> Context envContext = (Context)myContext.lookup("java:comp/env");

Ok.

> javax.sql.DataSource ds =
> (javax.sql.DataSource)envContext.lookup("jdbc/MySql");
> 
> conn = ds.getConnection();
> 
> stmt = conn.createStatement();

Ok.

> sql = "USE "+ dbName; // attempt to mymic jdbcConnect set for dbName!
> 
> stmt.execute(sql);

This is not necessary as you have already selected your db via the
connection URL.

> catch (SQLException E)
> 
> { lastException="*WARNING*"+sql+ ": connect SQL exception: "
> 
> + E.getMessage();
> 
> sysout.display(lastException);
> 
> //System.exit(4);
> 
> }
> catch(Exception eOther)
>
> { lastException="*WARNING*"+sql+ ": connect Other exception: "
>
> + eOther.getMessage();
>
> sysout.display(lastException);
>
> //System.exit(4);
>
> }

So, the above is the source of the error message which has all your
extra stuff like "*WARNING*Connection to jdbc/MySql:: connect SQL
exception:" plus the message from the real exception. I don't recognize
"Cannot create resource instance" so it would be helpful to show the
full stack trace and the real exception that caused the message to print.

I would recommend not catching "Exception" unless there is a good reason
to do so: allow the exception to propagate up the stack to a place where
it can be appropriately caught and dealt with, or at least logged
properly. What happens when this code fails and the "conn" member isn't
set properly? I'm guessing you either get NullPointerExceptions later in
your code, or you have to have a bunch of null checking in your query
code which is kind of ugly.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEUEARECAAYFAktd3f0ACgkQ9CaO5/Lv0PD6CgCXWjgZIBoBQrgS7ciU7Y4L8TGt
TQCbBC+bDwqmlEgAeiCXp/PdeweDFWM=
=aaxM
-----END PGP SIGNATURE-----

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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Steve Ryder <sr...@jsrsys.com>.
When I remove the factory line I now get:  Cannot create resource instance
2010-01-25 15:56:06:*WARNING*Connection to jdbc/MySql:: connect Other 
exception: Cannot create resource instance
2010-01-25 15:56:06:Driver=com.mysql.jdbc.Driver

The libraries are all in common\lib.  The ones I have added since the 5.5 
install are:
jsrweb (my Java code), mysql-connector-java-5.0.8-bin.jar,
naming-common.jar, naming-java.jar, mail.jar, and activation.jar.

I picked 5.5 because it is not getting active develpment, yet supports Java 
1.5, and has all the features I need hoping to minimize incompatabilities.

My Java "connect" code reads:   (indentation was lost when I copied)
private void connect(String dbName)

{

lastException = "OK";

try

{

// Class.forName("org.gjt.mm.mysql.Driver");  <---I changed this last night 
hoping to fix problem.

sysout.display("Driver=com.mysql.jdbc.Driver");

Class.forName("com.mysql.jdbc.Driver");

}

catch (Exception E) {lastException=" Unable to load driver"; 
E.printStackTrace();

sysout.display(lastException);}


try

{

sql = "Connection to jdbc/MySql:";

Context myContext = new InitialContext();

Context envContext = (Context)myContext.lookup("java:comp/env");

javax.sql.DataSource ds = 
(javax.sql.DataSource)envContext.lookup("jdbc/MySql");

conn = ds.getConnection();

stmt = conn.createStatement();

sql = "USE "+ dbName; // attempt to mymic jdbcConnect set for dbName!

stmt.execute(sql);

sysout.display("**"+sql + ": connection to jdbc/MySql established.");

}

catch (SQLException E)

{ lastException="*WARNING*"+sql+ ": connect SQL exception: "

+ E.getMessage();

sysout.display(lastException);

//System.exit(4);

}

catch(Exception eOther)

{ lastException="*WARNING*"+sql+ ": connect Other exception: "

+ eOther.getMessage();

sysout.display(lastException);

//System.exit(4);

}

}



----- Original Message ----- 
From: "Caldarale, Charles R" <Ch...@unisys.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, January 25, 2010 8:52 AM
Subject: RE: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource


>> From: Steve Ryder [mailto:sryder@jsrsys.com]
>> Subject: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to
>> javax.sql.DataSource
>>
>> <Resource name="jdbc/MySql" auth="Container"
>> type="javax.sql.Datasource"
>> factory="org.apache.commons.dbcp.BasicDataSourceFactory"
>
> The specified factory is for the standard Apache commons DBCP, not the one 
> bundled with Tomcat.  You might try removing it and let the Tomcat DBCP 
> factory do its thing.
>
>> My jdbc driver jar is: mysql-connector-java-5.0.8-bin.jar
>
> Where is the JDBC jar located?
>
> Since you're upgrading, why not upgrade to 6.0.x?  (5.5 is not getting 
> much in the way of active development these days.)
>
> - 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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


RE: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Steve Ryder [mailto:sryder@jsrsys.com]
> Subject: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to
> javax.sql.DataSource
> 
> <Resource name="jdbc/MySql" auth="Container"
> type="javax.sql.Datasource"
> factory="org.apache.commons.dbcp.BasicDataSourceFactory"

The specified factory is for the standard Apache commons DBCP, not the one bundled with Tomcat.  You might try removing it and let the Tomcat DBCP factory do its thing.

> My jdbc driver jar is: mysql-connector-java-5.0.8-bin.jar

Where is the JDBC jar located?

Since you're upgrading, why not upgrade to 6.0.x?  (5.5 is not getting much in the way of active development these days.)

 - 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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Steve Ryder <sr...@jsrsys.com>.
You "win the prize" for fixing the cast/resource instance errors at line 
504.
I failed to notice the "HumpInTheCamel".
I changed the s to S and now I get an even more weird error at line 506
506: conn = ds.getConnection();
507: sysout.display("JsrSQL: conn = ds successfull");

I am going to put the factory= statement back in to see if anything changes 
now.

2010-01-26 05:20:33:*WARNING*Connection to jdbc/MySql:: connect SQL 
exception: Cannot create PoolableConnectionFactory (Server connection 
failure during transaction. Due to underlying exception: 
'java.io.CharConversionException'. ** BEGIN NESTED EXCEPTION ** 
java.io.CharConversionException STACKTRACE: java.io.CharConversionException 
at gnu.gcj.convert.Input_iconv.read(libgcj.so.81) at 
java.lang.String.init(libgcj.so.81) at java.lang.String.(libgcj.so.81) at 
com.mysql.jdbc.SingleByteCharsetConverter.(SingleByteCharsetConverter.java:153) 
at 
com.mysql.jdbc.SingleByteCharsetConverter.initCharset(SingleByteCharsetConverter.java:108) 
at 
com.mysql.jdbc.SingleByteCharsetConverter.getInstance(SingleByteCharsetConverter.java:86) 
at com.mysql.jdbc.Connection.getCharsetConverter(Connection.java:3505) at 
com.mysql.jdbc.Statement.(Statement.java:290) at 
com.mysql.jdbc.Connection.createStatement(Connection.java:3123) at 
com.mysql.jdbc.Connection.createStatement(Connection.java:3103) at 
com.mysql.jdbc.Connection.loadServerVariables(Connection.java:4475) at 
com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4062) at 
com.mysql.jdbc.Connection.createNewIO(Connection.java:2940) at 
com.mysql.jdbc.Connection.(Connection.java:1555) at 
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) 
at 
org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) 
at 
org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294) 
at 
org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247) 
at 
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221) 
at 
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) 
at com.jsrsys.web.JsrSQL.connect(JsrSQL.java:506) at 
com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86) at 
com.jsrsys.web.JsrSQL.(JsrSQL.java:42) at 
org.apache.jsp.AppList_jsp._jspService(AppList_jsp.java:157) at 
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) 
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) 
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at 
java.lang.reflect.Method.invoke(libgcj.so.81) at 
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244) at 
java.security.AccessController.doPrivileged(libgcj.so.81) at 
javax.security.auth.Subject.doAsPrivileged(libgcj.so.81) at 
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276) at 
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162) 
at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:262) 
at 
org.apache.catalina.core.ApplicationFilterChain.access$0(ApplicationFilterChain.java:192) 
at 
org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:171) 
at java.security.AccessController.doPrivileged(libgcj.so.81) at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:167) 
at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) 
at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174) 
at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) 
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:544) 
at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) 
at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151) 
at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874) 
at 
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) 
at 
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) 
at 
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) 
at 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) 
at java.lang.Thread.run(libgcj.so.81) ** END NESTED EXCEPTION ** Attempted 
reconnect 3 times. Giving up.)
2010-01-26 05:20:28:JsrSQL: DataSource cast successfull
2010-01-26 05:20:28:JsrSQL: Context cast successfull
----- Original Message ----- 
From: "Konstantin Kolinko" <kn...@gmail.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, January 25, 2010 3:14 PM
Subject: Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource


> 2010/1/25 Steve Ryder <sr...@jsrsys.com>:
>> <Resource name="jdbc/MySql" auth="Container" type="javax.sql.Datasource"
>
> The above should be "javax.sql.DataSource"
>
>
> Do you have any references to this resource in your web.xml file?
>
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


RE: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Steve Ryder [mailto:sryder@jsrsys.com]
> Subject: Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to
> javax.sql.DataSource
> 
> Oops:
> sryder@srv:~$ java -version
> java version "1.5.0"
> gij (GNU libgcj) version 4.2.3 (Ubuntu 4.2.3-2ubuntu6)

A very big oops.

> I need to replace the java install with the Sun version.

Correct; replace the toy JVM with a real one.

 - 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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Steve Ryder <sr...@jsrsys.com>.
Oops:
sryder@srv:~$ java -version
java version "1.5.0"
gij (GNU libgcj) version 4.2.3 (Ubuntu 4.2.3-2ubuntu6)

Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
sryder@srv:~$ which java
/usr/bin/java
sryder@srv:~$

OK, I think I see the problem.  I contracted out the construction of this 
server.  I need to replace the java install with the Sun version.  Do you 
agree?
----- Original Message ----- 
From: "Bob Hall" <rf...@yahoo.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Tuesday, January 26, 2010 1:47 AM
Subject: Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource


> Steve,
>
> --- On Mon, 1/25/10 at 10:50 PM, Steve Ryder <sr...@jsrsys.com> wrote:
>
>> I understand what you mean by don't
>> use, but "I" am not using it.
>> What do I need to change so that it is not used?
>> How might I track down the offending library?
>
> What do you get when you type the following commands:
>
> $  java -version
>
> $  which java
>
> - Bob
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Bob Hall <rf...@yahoo.com>.
Steve,

--- On Mon, 1/25/10 at 10:50 PM, Steve Ryder <sr...@jsrsys.com> wrote:

> I understand what you mean by don't
> use, but "I" am not using it.
> What do I need to change so that it is not used?
> How might I track down the offending library?

What do you get when you type the following commands:

$  java -version

$  which java

- Bob



      

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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Steve Ryder <sr...@jsrsys.com>.
I understand what you mean by don't use, but "I" am not using it.
What do I need to change so that it is not used?
How might I track down the offending library?
----- Original Message ----- 
From: "Konstantin Kolinko" <kn...@gmail.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Tuesday, January 26, 2010 12:29 AM
Subject: Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource


> 2010/1/26 Steve Ryder <sr...@jsrsys.com>:
>> at gnu.gcj.convert.Input_iconv.read(libgcj.so.81)
>
> Stop right there. Do not use GNU "Java" for anything.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/1/26 Steve Ryder <sr...@jsrsys.com>:
> at gnu.gcj.convert.Input_iconv.read(libgcj.so.81)

Stop right there. Do not use GNU "Java" for anything.

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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Steve Ryder <sr...@jsrsys.com>.
I put the factory statement back in context.xml and I get the same error 
again (only this time I have added code to the SQL exception logic to 
display the stack trace stopping at the line that invoced the jsp that calls 
JsrSQL.  All the "trace" that is part of the message appears to me to be the 
same as was in the previous email (which did not have the factory line in 
context.xml).

FYI the factory line is: 
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
The only context.xml file is in the etc directory and thus applies to all 
domains.
The main difference is for 5.5 vs. 5.0 is that there is one Resource 
statement in context.xml
vs. having a resource link in context.xml for each project and one Resource 
statement in server.xml.

PS: Note the Stack= lines at the bottom.  All the stuff before them from 
"Cannot create" down is part of the getMessage() return variable.   Note the 
slight difference in line #s.  Stack(0) has line 1225 vs. 1221 in the "stack 
dump" part of the getMessage() line.

2010-01-26 05:38:29:*WARNING*Connection to jdbc/MySql:: connect SQL 
exception: Cannot create PoolableConnectionFactory (Server connection 
failure during transaction. Due to underlying exception: 
'java.io.CharConversionException'. ** BEGIN NESTED EXCEPTION ** 
java.io.CharConversionException STACKTRACE: java.io.CharConversionException 
at gnu.gcj.convert.Input_iconv.read(libgcj.so.81) at 
java.lang.String.init(libgcj.so.81) at java.lang.String.(libgcj.so.81) at 
com.mysql.jdbc.SingleByteCharsetConverter.(SingleByteCharsetConverter.java:153) 
at 
com.mysql.jdbc.SingleByteCharsetConverter.initCharset(SingleByteCharsetConverter.java:108) 
at 
com.mysql.jdbc.SingleByteCharsetConverter.getInstance(SingleByteCharsetConverter.java:86) 
at com.mysql.jdbc.Connection.getCharsetConverter(Connection.java:3505) at 
com.mysql.jdbc.Statement.(Statement.java:290) at 
com.mysql.jdbc.Connection.createStatement(Connection.java:3123) at 
com.mysql.jdbc.Connection.createStatement(Connection.java:3103) at 
com.mysql.jdbc.Connection.loadServerVariables(Connection.java:4475) at 
com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4062) at 
com.mysql.jdbc.Connection.createNewIO(Connection.java:2940) at 
com.mysql.jdbc.Connection.(Connection.java:1555) at 
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) 
at 
org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) 
at 
org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294) 
at 
org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247) 
at 
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221) 
at 
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880) 
at com.jsrsys.web.JsrSQL.connect(JsrSQL.java:506) at 
com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86) at 
com.jsrsys.web.JsrSQL.(JsrSQL.java:42) at 
org.apache.jsp.AppList_jsp._jspService(AppList_jsp.java:157) at 
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) 
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) 
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at 
java.lang.reflect.Method.invoke(libgcj.so.81) at 
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244) at 
java.security.AccessController.doPrivileged(libgcj.so.81) at 
javax.security.auth.Subject.doAsPrivileged(libgcj.so.81) at 
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276) at 
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162) 
at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:262) 
at 
org.apache.catalina.core.ApplicationFilterChain.access$0(ApplicationFilterChain.java:192) 
at 
org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:171) 
at java.security.AccessController.doPrivileged(libgcj.so.81) at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:167) 
at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) 
at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174) 
at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) 
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:544) 
at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) 
at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151) 
at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874) 
at 
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) 
at 
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) 
at 
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) 
at 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) 
at java.lang.Thread.run(libgcj.so.81) ** END NESTED EXCEPTION ** Attempted 
reconnect 3 times. Giving up.)
2010-01-26 
05:38:29:Stack(6)=org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
2010-01-26 
05:38:29:Stack(5)=org.apache.jsp.AppList_jsp._jspService(AppList_jsp.java:157)
2010-01-26 05:38:29:Stack(4)=com.jsrsys.web.JsrSQL.(JsrSQL.java:42)
2010-01-26 
05:38:29:Stack(3)=com.jsrsys.web.JsrSQL.setDataBaseName(JsrSQL.java:86)
2010-01-26 05:38:29:Stack(2)=com.jsrsys.web.JsrSQL.connect(JsrSQL.java:506)
2010-01-26 
05:38:29:Stack(1)=org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
2010-01-26 
05:38:29:Stack(0)=org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
2010-01-26 05:38:24:JsrSQL: DataSource cast successfull
2010-01-26 05:38:24:JsrSQL: Context cast successfull

----- Original Message ----- 
From: "Konstantin Kolinko" <kn...@gmail.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Monday, January 25, 2010 3:14 PM
Subject: Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to 
javax.sql.DataSource


> 2010/1/25 Steve Ryder <sr...@jsrsys.com>:
>> <Resource name="jdbc/MySql" auth="Container" type="javax.sql.Datasource"
>
> The above should be "javax.sql.DataSource"
>
>
> Do you have any references to this resource in your web.xml file?
>
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


Re: Tomcat 5.5 org.apache.naming.ResourceRef cannot be cast to javax.sql.DataSource

Posted by Konstantin Kolinko <kn...@gmail.com>.
2010/1/25 Steve Ryder <sr...@jsrsys.com>:
> <Resource name="jdbc/MySql" auth="Container" type="javax.sql.Datasource"

The above should be "javax.sql.DataSource"


Do you have any references to this resource in your web.xml file?


Best regards,
Konstantin Kolinko

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