ClassCastException -- Can't find the error

i've searched through the forums regarding this error, and i can't pinpoint why i'm getting this error.

i'm using a <jsp:useBean> tag with scope=application to declare a database connection pool. when the webserver starts, everything works fine for about 5 min, then i get the following error:

java.lang.ClassCastException: DBConnectionPool

at _0002faccount_0005flogIn_0002ejspaccount_0005flogIn_jsp_0._jspService(_0002faccount_0005flogIn_0002ejspaccount_0005flogIn_jsp_0.java:68)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)

at org.apache.tomcat.core.Handler.service(Handler.java:287)

at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)

at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)

at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)

at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)

at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)

at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)

at java.lang.Thread.run(Thread.java:484)

is my DBConnectionPool timing out? i KNOW the pool is working, since i'm able to access data in the DB for about 5 min. I could really use some help here. thanks everyone.

[2053 byte] By [wireframe] at [2007-9-26 2:38:52]
# 1

Does this happen when you try to use the login page that you're getting this error on?

It would be helpful if you showed us some code of what you're doing. You are casting the DBConnectionPool when you get it from the the application scope correct?

something like

java.sql.Connection conn = (class.path.DBConnectionPool)session.getAttribute("db").getConnection();

Let's see some code of the page you're getting an error from and the one that you use to put the DBConnectionPool into the application scope.

Hope that helps,

Bryan

bryanwclark at 2007-6-29 10:10:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

The pool may be working but it looks as if a non-DBConnection is getting pooled in with the connections and when it gets pulled out there is a class cast exception. I would track down every single use of the add-to-pool() method and ensure that only DBConnections are pooled. To completely irradicate the problem, use a typesafe API which will pool and depool only the objects of the exact type you need.

smiths at 2007-6-29 10:10:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

thanks for the replies. here's the code in my login page:

<!-- Connection Pool to User Database -->

<jsp:useBean id="connPoolUser" scope="page" class="DBConnectionPool" >

<jsp:setProperty name="connPoolUser" property="driver" value="interbase.interclient.Driver" />

<jsp:setProperty name="connPoolUser" property="url" value="jdbc:oracle:thin:@ip:host" />

<jsp:setProperty name="connPoolUser" property="username" value="user" />

<jsp:setProperty name="connPoolUser" property="password" value="user" />

</jsp:useBean>

<!-- Connection Pool to Product Database -->

<jsp:useBean id="connPoolProduct" scope="page" class="DBConnectionPool" >

<jsp:setProperty name="connPoolProduct" property="driver" value="interbase.interclient.Driver" />

<jsp:setProperty name="connPoolProduct" property="url" value="jdbc:oracle:thin:@ip:host" />

<jsp:setProperty name="connPoolProduct" property="username" value="user" />

<jsp:setProperty name="connPoolProduct" property="password" value="user" />

</jsp:useBean>

<jsp:useBean id="user" scope="session" class="User">

</jsp:useBean>

does it matter that i'm trying to declare 2 instances of the connection Pool? also, inside my pages that use the connection pool, i do the following:

<jsp:useBean id="objConn" scope="page" class="DBConnection"></jsp:useBean>

if (objConn.getConnection( connPoolProduct ) )

{

perform my operations here

}

sometimes, i also get an error:

variable connPoolProduct undefined.

wierd since it's an application variable. any suggestions?

wireframe at 2007-6-29 10:10:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
sorry, the 2 DBConnectionPool beans, ARE declared as scope=application in my jsp pages. I had a typo when posting.
wireframe at 2007-6-29 10:10:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

why are you doing

<jsp:useBean id="connPoolUser" scope="page" class="DBConnectionPool" >

</jsp:useBean>

I thought the syntax is:

<jsp:useBean id="connPoolUser" scope="page" class="DBConnectionPool" />

Anyways, have you re-compiled the pool object after starting the server? That sometimes would give an error like that. Prolly not but just had to ask :)

also, are you using tomcat? If so, check which line is giving the error. Sometimes it helps. The code generated for you jsp page is in the "work" dir in your tomcat dir, and the file it is in shows in the stacktrace along with the line number where the error is at. In this case it would be line 68 in a file named

_0002faccount_0005flogIn_0002ejspaccount_0005flogIn_jsp_0._jspService(_0002faccount_0005flogIn_0002ejspaccount_0005flogIn_jsp_0.java

-t

teka at 2007-6-29 10:10:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

you can use the </jsp:useBean> tag if you want to set variables when the object is created. if you do setParameter inbetween the <jsp:useBean> tag and the </jsp:useBean> tag, the values will ONLY be set when the object is first created. if you do setParameter outside of the <jsp:useBean> - </jsp:useBean> tags, the variables will be set each time the page is hit. since these are application variables, i only wanted to declare and set the variables once throughout the life of the object.

thanks for the advice about the tomcat directory. i'll look into it, and see if i can find anything in there. so far, it seems like the variable is just loosing it's scope, because i'm getting hit "sometimes" with a "variable Undefined" error. so, i've got to try and track down why that's happening.

wireframe at 2007-6-29 10:10:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
I have seen, mostly this error occurs while u have same file more than one place on ur machine.-mamtta
mamtta at 2007-6-29 10:10:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
thanks for the advice. actually there are several developers working on this machine......and two other people are working on DBConnection beans, so it is VERY possible that someone is messing with the same names. i'll have to look into. and for that, you get the duke dollars!!!
wireframe at 2007-6-29 10:10:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...