RE: Oracle/JAVA Connections

  • From: "Justin Cave (DDBC)" <jcave@xxxxxxxxxxx>
  • To: "LeRoy Kemnitz" <lkemnitz@xxxxxxxx>
  • Date: Wed, 1 Jun 2005 11:09:11 -0600

You're putting the connection logic in a JavaBean, then, right?  The
same principle would apply-- you would probably open and close the
connection in whatever method fetched data from the database.  The
general principle is that your middle tier only has the database
connection open for an instant for any particular user interaction and
the application server takes care of handing out connections from the
connection pool to the particular EJB/ servlet/ JSP that needs it.  It's
normal and expected that every time a particular user goes to a
different page they will (potentially) be using a different physical
connection.  Since HTTP is stateless, the application server has no idea
how to associate a particular connection object with requests coming
from a particular browser, which is what it sounds like you are
expecting to happen.

Justin Cave =20
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC

-----Original Message-----
From: LeRoy Kemnitz [mailto:lkemnitz@xxxxxxxx]=20
Sent: Wednesday, June 01, 2005 12:40 PM
To: Justin Cave (DDBC)
Cc: oracle-l@xxxxxxxxxxxxx
Subject: Re: Oracle/JAVA Connections

We tried to implement the MVC Architecture.  We tried to keep the=20
actions and JSPs dumb.  We try to do the database connections in the=20
business objects layer below the JSPs.  So the action just calls the=20
method in the Business Objects to retrieve the rows and all the JSP=20
knows is that it gets rows.=20



Justin Cave (DDBC) wrote:

>The normal pattern for Java server pages is to open a connection as the
>first action on the page and to close that connection as the last
action
>on the page (taking care that the close happens whether the page
>generates an exception or not).  The application will generally
maintain
>a connection pool so you won't be opening physical connections every
>time, you are just pulling a connection from the pool and returning a
>connection to the pool.
>
>My guess is that when you are doing the connection pooling you are
>holding on to the same Connection object after the login has failed.
>You would normally close that Connection and open a new one using the
>new credentials.
>
>Justin Cave =20
>Distributed Database Consulting, Inc.
>http://www.ddbcinc.com/askDDBC
>
>-----Original Message-----
>From: oracle-l-bounce@xxxxxxxxxxxxx
>[mailto:oracle-l-bounce@xxxxxxxxxxxxx] On Behalf Of LeRoy Kemnitz
>Sent: Wednesday, June 01, 2005 11:53 AM
>To: oracle-l@xxxxxxxxxxxxx
>Subject: Oracle/JAVA Connections
>
>All -
>
>I am having problems with our Java app and hope someone here can help.

>We are using Oracle dedicated connections.  We tried the Connection=20
>pooling with Oracle Impl but had no luck.  The problems we are having=20
>are this -
>
>1.  When we try the dedicated connections (no pooling), the app starts=20
>up and the first user logs in fine.  They retrieve and all is fine.
The
>
>same person logs in again in new and 2nd browser, the connection is
made
>
>just fine.  But when we logout, just the last connection shows as being

>disconnected fro Oracle.  The other connection is left as orphan.  The=20
>orig browser can no longer function and needs to be closed.  What are
we
>
>missing?  Do we need to name each connection uniquely and call the
close
>
>for each one as they close?  I thought Java would attach one connection

>to each session and close it when requested.
>
>2.  When we use connection pooling, the pool is defined as Dynamic and=20
>using the OracleImpl.  We connect outside the pool first to be sure of=20
>good login.  Once we have good login we move the connection to the pool

>and getConnection.  This disconnects the orig connection and is added
to
>
>the pool.  This works great.  Now we try to login incorrectly the first

>time.  This works and prompts you telling us to 'Login with Correct=20
>Username/password'.  But if we give it a correct set of=20
>username/password then it returns database error.  It seems as though
it
>
>keeps the error in memory for that userid.  We can go out and whack the

>Work files for Tomcat and force it to re-compile and then it works
great
>
>the first time.  We change the struts-config to not cache but it still=20
>did it.  We then tried to check with the Tomcat Admin to see if he knew

>of a caching parm for Tomcat.  He said 'Not that he knew of.'  Is there

>a parm for Tomcat to force re-compile each time?  Are we missing=20
>something else?  Any help would be appreciated.
>
>By the way, our platform is WebSphere 5.1.2  on Windows pc with Tomcat=20
>locally.   We also have a web server on AIX/Unix running Tomcat.  We=20
>develop locally and deploy to the test server.
>
>LeRoy
>
>--
>//www.freelists.org/webpage/oracle-l
>
>
> =20
>

--=20
LeRoy Kemnitz
UW System Administration
Database Administrator
780 Regent Street, #246
Madison, WI 53714
Phone: (608) 265 -5775
Fax: (608) 265 - 2090

--
//www.freelists.org/webpage/oracle-l

Other related posts: