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


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

Reply via email to