Georges,

It is not recommended that you place the Connection in the users session.
This is a potential hazard which can cause lots of open connections to the
database.

It is also not recommended that you have database interaction directly in
your Action classes. Its best to encapsulate database interaction within
a business object. If User is your business object, then something like

User.login(userId, password);

, where the login() of User contains all the necessary logic for logging
the customer into the system (querying the database, validating password,
etc...)

The architecture of the business layer in Struts has been a topic of much
discussion on this list. Search the archives for DAO (data access object).

-Display the login screen
-User submits request to login
-LoginAction extracts the user id and password from the form
-LoginAction gets User object
-User object logs in the user
-LoginAction forwards to next step


This way the Connection is accessed, used, closed and released in a single
business method which is reusable.

HTH,

robert



> -----Original Message-----
> From: Georges [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 13, 2002 2:21 AM
> To: [EMAIL PROTECTED]
> Subject: Problem with maintaining a database connection in a session
> bean
>
>
>
> Hi,
>
> I'm trying to build a small pilot application with Struts.
> My ultimate goal is a dynamic web application with
> intensive use of database.
> My database is Oracle 8.
> The problem is following:
> in 'LoginAction' I set up a database connection
> (java.sql.Connection variable) with Oracle
> database. I "save" it
> in the User session bean as a bean-variable.
> Then I test it in a jsp-page.
> Everything seems to work: the variable containing
> the database connection is created and put into
> User bean (something like ...setConnection(connection)).
> The first time the jsp-page works well: the connection
> comes from "conn=user.get_connection()", I can send
> a select-query to the database and display the
> outcome etc.
> But if I refresh the jsp-page, then at a certain
> moment an error message is displayed:
> java.sql.SQLException: Closed Connection
>
> I undestand that the connection gets somehow
> lost in the session bean. This happens especially
> when I test with two parallel sessions
> (one from IE and another from Netscape).
>
> Can anyone help me? Where could the connection go lost?
>
> Thanks,
> George.
>
>
> P.S
> I have to save a connection with every session
> because this way I can get user info from
> the database and administer database privileges.
> I can't use just a connection pool and
> get a connection from there every time I need
> something from the database.
> I have to lock records, maintain transactions etc.,
> so every user/session needs to have an
> individual database connection.
>
> -----------------------------------------
> Teatri- , kino- ja kontserdipiletid n||d hiirekliki kaugusel!
> http://www.hot.ee
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to