Re: GenericDataSource best practise?

2003-08-22 Thread David Graham
--- Andy Cheng [EMAIL PROTECTED] wrote:
 Hi, currently I have something like the code below on every action, is
 this the normal way of getting the connection?  And how would normal
 people do if they want to make some data access objects, which contain
 all the methods like insert, select etc, while the Action class will
 purely do logic, for example only contain this kind of statements:
 HashMap hmResult = dataAccess.getAllClients();  Thanks.

Most apps lookup the DataSource from JNDI.  You configure the DataSource
in your container instead of struts-config.xml.

 
 public ActionForward perform(ActionMapping mapping, ActionForm form,
 HttpServletRequest request, HttpServletResponse response) {
 ServletContext context = servlet.getServletContext();
 try {
 DataSource dataSource =
 (DataSource)context.getAttribute(Action.DATA_SOURCE_KEY);
 Connection conn = dataSource.getConnection();
 Statement stmt = conn.createStatement();
 ResultSet rs = stmt.executeQuery(SELECT * FROM aTable);
 while(rs.next()) {
 //...
 }
 
 } catch (Exception e) {
 e.printStackTrace();
 }
 return (mapping.findForward(xxx));
   }

This is absolutely the wrong way of doing database access.  You *must*
properly cleanup JDBC resources on every access, including when exceptions
are thrown.  Doing this cleanup is tedious, boring, and error prone so I
created the Mapper project in the Jakata Commons Sandbox.  Check it out;
it significantly reduces the size of database access code as well as
isolates your app. from the persistence mechanism so you can swap it
later.

David

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


__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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



Re: GenericDataSource

2003-07-04 Thread Nicolas De Loof
Struts 1.1 has dependencies to some commons projects. First 1.1 pre-release of Struts 
used commons-dbcp for the
DataSource functionnality in replacement of GenericDataSource .

Waiting for this commons to get stable before releasing 1.1 final, Struts commiters 
agreed to go back to
GenericDataSource because commons-dbcp looked very unstable.

Struts-legacy has been created to include this class outside of Struts core as 
DefaultDataSource have been deprecated :
Future Struts version will set the datasource type attribute to mandatory, so you 
will have to set your selected
DataSource (that can be commons-dbcp, and lot's of us use container pool service and 
JNDI to get a DataSource).

Nico.




 Can someone explain why GenericDataSource was moved to lagacy?

 I have been using it successfully as a JINI DataSourse - have others experienced
 problems? - if so, what problems?

 db


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


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



RE: GenericDataSource

2003-07-04 Thread Steve Raeburn
The short answer is that GenericDataSource was originally deprecated in
favour of Commons DBCP.

Unfortunately, problems with DBCP that could not be fixed in time for the
1.1 release meant that DBCP was removed and 1.1 reverted back to Generic
DataSource.

This is only a temporary measure so GenericDataSource was packaged
separately from the main struts jar.

Steve

 -Original Message-
 From: David Bolsover [mailto:[EMAIL PROTECTED]
 Sent: July 4, 2003 4:04 AM
 To: Struts User
 Subject: GenericDataSource



 Can someone explain why GenericDataSource was moved to lagacy?

 I have been using it successfully as a JINI DataSourse - have
 others experienced
 problems? - if so, what problems?

 db


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






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



RE: GenericDataSource

2003-07-04 Thread Steve Raeburn
Stop doing that! :-)

Steve

 -Original Message-
 From: Nicolas De Loof [mailto:[EMAIL PROTECTED]
 Sent: July 4, 2003 4:15 AM
 To: Struts Users Mailing List; [EMAIL PROTECTED]
 Subject: Re: GenericDataSource
 
 
 Struts 1.1 has dependencies to some commons projects. First 1.1 
 pre-release of Struts used commons-dbcp for the
 DataSource functionnality in replacement of GenericDataSource .
 
 Waiting for this commons to get stable before releasing 1.1 
 final, Struts commiters agreed to go back to
 GenericDataSource because commons-dbcp looked very unstable.
 
 Struts-legacy has been created to include this class outside of 
 Struts core as DefaultDataSource have been deprecated :
 Future Struts version will set the datasource type attribute 
 to mandatory, so you will have to set your selected
 DataSource (that can be commons-dbcp, and lot's of us use 
 container pool service and JNDI to get a DataSource).
 
 Nico.
 
 
 
 
  Can someone explain why GenericDataSource was moved to lagacy?
 
  I have been using it successfully as a JINI DataSourse - have 
 others experienced
  problems? - if so, what problems?
 
  db
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 


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



Re: GenericDataSource

2003-07-04 Thread Nicolas De Loof
I promise to let you respond first to the next one ! ;-)

Nico.


 Stop doing that! :-)
 
 Steve
 
  -Original Message-
  From: Nicolas De Loof [mailto:[EMAIL PROTECTED]
  Sent: July 4, 2003 4:15 AM
  To: Struts Users Mailing List; [EMAIL PROTECTED]
  Subject: Re: GenericDataSource
  
  
  Struts 1.1 has dependencies to some commons projects. First 1.1 
  pre-release of Struts used commons-dbcp for the
  DataSource functionnality in replacement of GenericDataSource .
  
  Waiting for this commons to get stable before releasing 1.1 
  final, Struts commiters agreed to go back to
  GenericDataSource because commons-dbcp looked very unstable.
  
  Struts-legacy has been created to include this class outside of 
  Struts core as DefaultDataSource have been deprecated :
  Future Struts version will set the datasource type attribute 
  to mandatory, so you will have to set your selected
  DataSource (that can be commons-dbcp, and lot's of us use 
  container pool service and JNDI to get a DataSource).
  
  Nico.
  
  
  
  
   Can someone explain why GenericDataSource was moved to lagacy?
  
   I have been using it successfully as a JINI DataSourse - have 
  others experienced
   problems? - if so, what problems?
  
   db
  
  
   -
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
  
  
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  
  
  
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]

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



RE: GenericDataSource

2003-07-04 Thread Steve Raeburn
It's 4.25am here. My brain is a little bit s - l - o - w .

Steve

 -Original Message-
 From: Nicolas De Loof [mailto:[EMAIL PROTECTED]
 Sent: July 4, 2003 4:24 AM
 To: Struts Users Mailing List; [EMAIL PROTECTED]
 Subject: Re: GenericDataSource


 I promise to let you respond first to the next one ! ;-)

 Nico.


  Stop doing that! :-)
 
  Steve
 
   -Original Message-
   From: Nicolas De Loof [mailto:[EMAIL PROTECTED]
   Sent: July 4, 2003 4:15 AM
   To: Struts Users Mailing List; [EMAIL PROTECTED]
   Subject: Re: GenericDataSource
  
  
   Struts 1.1 has dependencies to some commons projects. First 1.1
   pre-release of Struts used commons-dbcp for the
   DataSource functionnality in replacement of GenericDataSource .
  
   Waiting for this commons to get stable before releasing 1.1
   final, Struts commiters agreed to go back to
   GenericDataSource because commons-dbcp looked very unstable.
  
   Struts-legacy has been created to include this class outside of
   Struts core as DefaultDataSource have been deprecated :
   Future Struts version will set the datasource type attribute
   to mandatory, so you will have to set your selected
   DataSource (that can be commons-dbcp, and lot's of us use
   container pool service and JNDI to get a DataSource).
  
   Nico.
  
  
  
   
Can someone explain why GenericDataSource was moved to lagacy?
   
I have been using it successfully as a JINI DataSourse - have
   others experienced
problems? - if so, what problems?
   
db
   
   
   
 -
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
  
  
   -
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
  
  
  
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]

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






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



Re: GenericDataSource

2003-07-04 Thread Nicolas De Loof
That should be the reason why my 1.27 pm brain looks so quick ! Don't panic, I'm on 
holiday next week, you will have
the whole day to respond to struts-users.

Nico.


 It's 4.25am here. My brain is a little bit s - l - o - w .

 Steve

  -Original Message-
  From: Nicolas De Loof [mailto:[EMAIL PROTECTED]
  Sent: July 4, 2003 4:24 AM
  To: Struts Users Mailing List; [EMAIL PROTECTED]
  Subject: Re: GenericDataSource
 
 
  I promise to let you respond first to the next one ! ;-)
 
  Nico.
 
 
   Stop doing that! :-)
  
   Steve
  
-Original Message-
From: Nicolas De Loof [mailto:[EMAIL PROTECTED]
Sent: July 4, 2003 4:15 AM
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: Re: GenericDataSource
   
   
Struts 1.1 has dependencies to some commons projects. First 1.1
pre-release of Struts used commons-dbcp for the
DataSource functionnality in replacement of GenericDataSource .
   
Waiting for this commons to get stable before releasing 1.1
final, Struts commiters agreed to go back to
GenericDataSource because commons-dbcp looked very unstable.
   
Struts-legacy has been created to include this class outside of
Struts core as DefaultDataSource have been deprecated :
Future Struts version will set the datasource type attribute
to mandatory, so you will have to set your selected
DataSource (that can be commons-dbcp, and lot's of us use
container pool service and JNDI to get a DataSource).
   
Nico.
   
   
   

 Can someone explain why GenericDataSource was moved to lagacy?

 I have been using it successfully as a JINI DataSourse - have
others experienced
 problems? - if so, what problems?

 db



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



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


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



RE: GenericDataSource

2003-07-04 Thread David Bolsover
Nico /Steve

Thanks for the prompt replies - glad I stuck with GenericDataSource rather than
trying out the commons-dbpc offerings!

db

-Original Message-
From: Nicolas De Loof [mailto:[EMAIL PROTECTED]
Sent: 04 July 2003 12:15
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: Re: GenericDataSource


Struts 1.1 has dependencies to some commons projects. First 1.1 pre-release of
Struts used commons-dbcp for the
DataSource functionnality in replacement of GenericDataSource .

Waiting for this commons to get stable before releasing 1.1 final, Struts
commiters agreed to go back to
GenericDataSource because commons-dbcp looked very unstable.

Struts-legacy has been created to include this class outside of Struts core as
DefaultDataSource have been deprecated :
Future Struts version will set the datasource type attribute to mandatory,
so you will have to set your selected
DataSource (that can be commons-dbcp, and lot's of us use container pool service
and JNDI to get a DataSource).

Nico.




 Can someone explain why GenericDataSource was moved to lagacy?

 I have been using it successfully as a JINI DataSourse - have others
experienced
 problems? - if so, what problems?

 db


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



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



Re: GenericDataSource

2003-07-04 Thread Adam Hardy
woohoo - I just had a look at the dbcp bugzilla

http://issues.apache.org/bugzilla/buglist.cgi?bug_status=UNCONFIRMEDbug_status=NEWbug_status=ASSIGNEDbug_status=REOPENEDemail1=emailtype1=substringemailassigned_to1=1email2=emailtype2=substringemailreporter2=1bugidtype=includebug_id=changedin=votes=chfieldfrom=chfieldto=Nowchfieldvalue=product=Commonscomponent=Dbcpshort_desc=short_desc_type=allwordssubstrlong_desc=long_desc_type=allwordssubstrbug_file_loc=bug_file_loc_type=allwordssubstrkeywords=keywords_type=anywordsfield0-0-0=nooptype0-0-0=noopvalue0-0-0=cmdtype=doitorder=Reuse+same+sort+as+last+time

seems like they're still a few issues there to clear up.

David Bolsover wrote:
Nico /Steve

Thanks for the prompt replies - glad I stuck with GenericDataSource rather than
trying out the commons-dbpc offerings!
db

-Original Message-
From: Nicolas De Loof [mailto:[EMAIL PROTECTED]
Sent: 04 July 2003 12:15
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: Re: GenericDataSource
Struts 1.1 has dependencies to some commons projects. First 1.1 pre-release of
Struts used commons-dbcp for the
DataSource functionnality in replacement of GenericDataSource .
Waiting for this commons to get stable before releasing 1.1 final, Struts
commiters agreed to go back to
GenericDataSource because commons-dbcp looked very unstable.
Struts-legacy has been created to include this class outside of Struts core as
DefaultDataSource have been deprecated :
Future Struts version will set the datasource type attribute to mandatory,
so you will have to set your selected
DataSource (that can be commons-dbcp, and lot's of us use container pool service
and JNDI to get a DataSource).
Nico.




Can someone explain why GenericDataSource was moved to lagacy?

I have been using it successfully as a JINI DataSourse - have others
experienced

problems? - if so, what problems?

db

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




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



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


Re: GenericDataSource looping

2003-06-16 Thread Adam Hardy
You've left off the type attribute in the data-source tag. Try

data-source type=org.apache.commons.dbcp.BasicDataSource

don't you get any errors?

Richard Raquepo wrote:
Im use to use DBCP in Struts 1.1RC1
but then mo back to GenericDataSource in Struts 1.1RC2
but it seem's im having a problem with it. According to my console it seem's generic 
source is lopping endlessly...
429796 [tcp-accept-6802] INFO util.GenericDataSource  -createConnection()
429812 [tcp-accept-6802] INFO util.GenericDataSource  -Return new connection, 
activeCount=5, useCount=123
429812 [tcp-accept-6802] INFO util.GenericDataSource  -   getConnection()
429812 [tcp-accept-6802] INFO util.GenericDataSource  -Check for timeout, 
activeCount=4, useCount=123

my data-source configuration in my struts-config.xml looks like this:
  data-source key=DATASOURCE  
   set-property property=driverClass value=com.mysql.jdbc.Driver /
   set-property property=url value=jdbc:mysql://localhost/crmdev /
   set-property property=maxCount value=10 /
   set-property property=minCount value=5 /
   set-property property=user value=root /
   set-property property=password value=password /
  /data-source


has anybody experienced this before? what do i have to do to make it work?
or should i really change my datasource? i was thinking og using DBConnectionBroker? 
any ideas?
thanks.


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


Re: GenericDataSource looping

2003-06-16 Thread Richard Raquepo
i believe data-source type=org.apache.commons.dbcp.BasicDataSource is no
longer supported in struts1.1RC2.

- Original Message -
From: Adam Hardy [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, June 16, 2003 2:55 PM
Subject: Re: GenericDataSource looping


 You've left off the type attribute in the data-source tag. Try

 data-source type=org.apache.commons.dbcp.BasicDataSource

 don't you get any errors?

 Richard Raquepo wrote:
  Im use to use DBCP in Struts 1.1RC1
  but then mo back to GenericDataSource in Struts 1.1RC2
 
  but it seem's im having a problem with it. According to my console it
seem's generic source is lopping endlessly...
  429796 [tcp-accept-6802] INFO util.GenericDataSource  -
createConnection()
  429812 [tcp-accept-6802] INFO util.GenericDataSource  -Return new
connection, activeCount=5, useCount=123
  429812 [tcp-accept-6802] INFO util.GenericDataSource  -
getConnection()
  429812 [tcp-accept-6802] INFO util.GenericDataSource  -Check for
timeout, activeCount=4, useCount=123
  
 
  my data-source configuration in my struts-config.xml looks like this:
data-source key=DATASOURCE
 set-property property=driverClass value=com.mysql.jdbc.Driver /
 set-property property=url value=jdbc:mysql://localhost/crmdev /
 set-property property=maxCount value=10 /
 set-property property=minCount value=5 /
 set-property property=user value=root /
 set-property property=password value=password /
/data-source
 
  
  has anybody experienced this before? what do i have to do to make it
work?
  or should i really change my datasource? i was thinking og using
DBConnectionBroker? any ideas?
 
  thanks.


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





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



Re: GenericDataSource looping

2003-06-16 Thread Ted Husted
Any pool that supports the DataSource interface should work, including 
the BasicDataSource. The DBCP just isn't being bundled with Struts 
anymore. In a future release, the type property will be required, and 
you will have to provide your own DataSource implementation.

-Ted.

Richard Raquepo wrote:
i believe data-source type=org.apache.commons.dbcp.BasicDataSource is no
longer supported in struts1.1RC2.


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


Re: GenericDataSource looping

2003-06-16 Thread Ted Husted
If you are saying that these four lines appear over and over again, 
without ever establishing a connection, then please file a report in 
Bugzilla.

In a future release, the GenericDataSource will be unbundled and you 
will have to supply your own DataSource implementation. So, if you were 
planning on using another implementation, this would be a good a time as 
any to switch.

-Ted.

Richard Raquepo wrote:
Im use to use DBCP in Struts 1.1RC1
but then mo back to GenericDataSource in Struts 1.1RC2
but it seem's im having a problem with it. According to my console it seem's generic 
source is lopping endlessly...
429796 [tcp-accept-6802] INFO util.GenericDataSource  -createConnection()
429812 [tcp-accept-6802] INFO util.GenericDataSource  -Return new connection, 
activeCount=5, useCount=123
429812 [tcp-accept-6802] INFO util.GenericDataSource  -   getConnection()
429812 [tcp-accept-6802] INFO util.GenericDataSource  -Check for timeout, 
activeCount=4, useCount=123

my data-source configuration in my struts-config.xml looks like this:
  data-source key=DATASOURCE  
   set-property property=driverClass value=com.mysql.jdbc.Driver /
   set-property property=url value=jdbc:mysql://localhost/crmdev /
   set-property property=maxCount value=10 /
   set-property property=minCount value=5 /
   set-property property=user value=root /
   set-property property=password value=password /
  /data-source


has anybody experienced this before? what do i have to do to make it work?
or should i really change my datasource? i was thinking og using DBConnectionBroker? 
any ideas?
thanks.


--
Ted Husted,
Struts in Action http://husted.com/struts/book.html


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


Re: GenericDataSource

2001-06-14 Thread Chuck Amadi

Cheers Mark , as i was sure i came across it somewhere as i am on the connection 
pooling since i
made the generic Datasource URL work within postgresql and jsp, except i didn't like 
the result
so have any advice regarding forms /nested forms as sql statement retrieved the data 
from my db
but i wan it in a aesthetically pleasing manner.

Cheers chuck

Mark Johnson wrote:

 In Tomcat 3.2.1 the session timeout is set in 
$JAKARTA_HOME/build/tomcat/conf/web.xml. HTH...

  Date: Wed, 13 Jun 2001 14:51:21 +0100
  To: [EMAIL PROTECTED]
  From: Chuck Amadi [EMAIL PROTECTED]
  Subject: Re: GenericDataSource
  Message-ID: [EMAIL PROTECTED]
 
  Sorry,  anwser to the 1st question , the fact is the session is closed is
  because by default there is a 30 minute time out somewhere in xml doc's
  either tld or struts-config i'll have 2 take a look as im digesting all this
  at work and at home but there is definately a time out period.

--
The views expressed by the sender of this message don't
necessarily represent those of Brecon Beacons National Park
Authority. This message is intended for the addressee(s) only
and is sent in confidence; if you receive it in error, please can you
let us know (at [EMAIL PROTECTED]) and then destroy all copies.
Nid yw'r farn a fynegir gan anfonwr y neges hon o anghenraid yn
adlewyrchu barn Awdurdod Parc Cenedlaethol Bannau Brycheiniog.
Neges yw hon a fwriadwyd ar gyfer y derbynnydd/derbynyddion
yn unig ac fe'i hanfonir yn gyfrinachol; os ydych yn ei dderbyn
mewn camgymeriad, a fyddech gystal â rhoi gwybod i
ni (yn [EMAIL PROTECTED]) ac yna dilëwch bob copi.





RE: GenericDataSource

2001-06-13 Thread Jon.Ridgway

Hi,

Not sure how correct this is but.. when you use DataSource.getConnection ()
in struts your connection will be popped of a pool. 

You are responsible for closing statements and the connection when you have
finished with it. These may close automatically when they go out of scope,
but I wouldn't bank on it. Always add a finally block in which you
explicitly close your statement and the connection. The connection will then
be marked as available in the pool.

Jon.

-Original Message-
From: hunkpapa [mailto:[EMAIL PROTECTED]] 
Sent: 13 June 2001 12:06
To: [EMAIL PROTECTED]
Subject: GenericDataSource 

Hi,
I've some new questions
to GenericDataSource.
I put this in the struts-config.xml
  data-sources
data-source
   autoCommit=false
  description=Example Data Source Configuration
  driverClass=sun.jdbc.odbc.JdbcOdbcDriver
 maxCount=4
 minCount=2
 password=
  url=jdbc:odbc:TEST
 user=sa
/
  /data-sources

I works well.
Here my questiions:
- How does struts manage the connections, if the session is closed cause
the user is gone ? Does it close automatic ?
- How can I  share a pool of open connections between all of the
application's current users. ?






RE: GenericDataSource

2001-06-13 Thread David Winterfeldt

You need to call close() on the connection to return
it to the connection pool.  It will not go back to the
pool just because you loose a reference to it.  It is
important to catch exceptions and have a finally block
that makes sure this happens so connections don't get
lost.

David

--- Jon.Ridgway [EMAIL PROTECTED] wrote:
 Hi,
 
 Not sure how correct this is but.. when you use
 DataSource.getConnection ()
 in struts your connection will be popped of a pool. 
 
 You are responsible for closing statements and the
 connection when you have
 finished with it. These may close automatically when
 they go out of scope,
 but I wouldn't bank on it. Always add a finally
 block in which you
 explicitly close your statement and the connection.
 The connection will then
 be marked as available in the pool.
 
 Jon.
 
 -Original Message-
 From: hunkpapa [mailto:[EMAIL PROTECTED]] 
 Sent: 13 June 2001 12:06
 To: [EMAIL PROTECTED]
 Subject: GenericDataSource 
 
 Hi,
 I've some new questions
 to GenericDataSource.
 I put this in the struts-config.xml
   data-sources
 data-source
autoCommit=false
   description=Example Data Source
 Configuration
   driverClass=sun.jdbc.odbc.JdbcOdbcDriver
  maxCount=4
  minCount=2
  password=
   url=jdbc:odbc:TEST
  user=sa
 /
   /data-sources
 
 I works well.
 Here my questiions:
 - How does struts manage the connections, if the
 session is closed cause
 the user is gone ? Does it close automatic ?
 - How can I  share a pool of open connections
 between all of the
 application's current users. ?
 
 
 


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



Re: GenericDataSource

2001-06-13 Thread Chuck Amadi


Hi, Im a newbie myself albeit i did managed to succeed in the generi datasource
URI example.
1) the Struts manages to make a connection via the url IP address for
example mine is -
sql:url>jdbc:postgresql: / /111.15.1.10/test1/sql:url>
// test1 the name of my database in postgresql. thus you need to
exstablish your database driver mine wassql:driver>org.postgresql.Driver/sql:driver>
note diffrent drivers use different URL's it is also suggested that
you stray away from odbc (MSAccess) as JDBC-ODBC bridge driver is
used usually for prototyping purposes.
2) the session is either closed by pasing it's reference to the closeConnction
tag. and within unless your you are performing your own connection pooling
which im currently working on, thus if not you close it down sql:closeConnection
id="conn1" />
3) I hav eso far used the Datasource as it is generic and easier to
administer/config thus a connection pool is connections that can
be shared by multiple clients note that this is tediuosly but interestingly
long basically a connection is opened once and stays open until the
app is shut down thus if you need a connection it gets it from the pool
thru the datasource object and excutes a SQL statements. thus when the
connection is apparently closed the connection is returned to the pool
where it can be used by the next action that requires it. Thus the syntax
is sql:useDatasource> action implements a basic connection pool. Hence
i am still playing around with it.
Hope this helps as i seem 2 get good ideas from this community.
Cheers Chuck.
hunkpapa wrote:
Hi,
I've some new questions
to GenericDataSource.
I put this in the struts-config.xml
 data-sources>
 data-source
 autoCommit="false"
 description="Example Data Source Configuration"
 driverClass="sun.jdbc.odbc.JdbcOdbcDriver"
 maxCount="4"
 minCount="2"
 password=""

url="jdbc:odbc:TEST"

user="sa"
 />
 /data-sources>
I works well.
Here my questiions:
- How does struts manage the connections, if the session is closed
cause
the user is gone ? Does it close automatic ?
- How can I share a "pool" of open connections between all of
the
application's current users. ?
--
The views expressed by the sender of this message don't
necessarily represent those of Brecon Beacons National Park
Authority. This message is intended for the addressee(s) only
and is sent in confidence; if you receive it in error, please can you
let us know (at [EMAIL PROTECTED]) and then destroy all copies.
Nid yw'r farn a fynegir gan anfonwr y neges hon o anghenraid yn
adlewyrchu barn Awdurdod Parc Cenedlaethol Bannau Brycheiniog.
Neges yw hon a fwriadwyd ar gyfer y derbynnydd/derbynyddion
yn unig ac fe'i hanfonir yn gyfrinachol; os ydych yn ei dderbyn
mewn camgymeriad, a fyddech gystal  rhoi gwybod i
ni (yn [EMAIL PROTECTED]) ac yna dilwch bob copi.



Re: GenericDataSource

2001-06-13 Thread Chuck Amadi


oops me again i 4 got to mention that there is a set of interfaces that
connection pools implement ie
javax.sqlDatasource
javax.sql.ConnectionPoolDatasource
javax.sql.PooledConnection.
Thus you have the JDBC 2.0 Connection pool note that DBtags has replaced
JDBC tag library you may continue to use JDBC .
hunkpapa wrote:
Hi,
I've some new questions
to GenericDataSource.
I put this in the struts-config.xml
 data-sources>
 data-source
 autoCommit="false"
 description="Example Data Source Configuration"
 driverClass="sun.jdbc.odbc.JdbcOdbcDriver"
 maxCount="4"
 minCount="2"
 password=""

url="jdbc:odbc:TEST"

user="sa"
 />
 /data-sources>
I works well.
Here my questiions:
- How does struts manage the connections, if the session is closed
cause
the user is gone ? Does it close automatic ?
- How can I share a "pool" of open connections between all of
the
application's current users. ?

--
The views expressed by the sender of this message don't
necessarily represent those of Brecon Beacons National Park
Authority. This message is intended for the addressee(s) only
and is sent in confidence; if you receive it in error, please can you
let us know (at [EMAIL PROTECTED]) and then destroy all copies.
Nid yw'r farn a fynegir gan anfonwr y neges hon o anghenraid yn
adlewyrchu barn Awdurdod Parc Cenedlaethol Bannau Brycheiniog.
Neges yw hon a fwriadwyd ar gyfer y derbynnydd/derbynyddion
yn unig ac fe'i hanfonir yn gyfrinachol; os ydych yn ei dderbyn
mewn camgymeriad, a fyddech gystal  rhoi gwybod i
ni (yn [EMAIL PROTECTED]) ac yna dilwch bob copi.



Re: GenericDataSource

2001-06-13 Thread Chuck Amadi

Sorry,  anwser to the 1st question , the fact is the session is closed is
because by default there is a 30 minute time out somewhere in xml doc's
either tld or struts-config i'll have 2 take a look as im digesting all this
at work and at home but there is definately a time out period.

Hope this helps as it will mean i made my 1st contrubtion (makes a change )
Cheers newbie (chuck).



hunkpapa wrote:

 Hi,
 I've some new questions
 to GenericDataSource.
 I put this in the struts-config.xml
   data-sources
 data-source
autoCommit=false
   description=Example Data Source Configuration
   driverClass=sun.jdbc.odbc.JdbcOdbcDriver
  maxCount=4
  minCount=2
  password=
   url=jdbc:odbc:TEST
  user=sa
 /
   /data-sources

 I works well.
 Here my questiions:
 - How does struts manage the connections, if the session is closed cause
 the user is gone ? Does it close automatic ?
 - How can I  share a pool of open connections between all of the
 application's current users. ?

--
The views expressed by the sender of this message don't
necessarily represent those of Brecon Beacons National Park
Authority. This message is intended for the addressee(s) only
and is sent in confidence; if you receive it in error, please can you
let us know (at [EMAIL PROTECTED]) and then destroy all copies.
Nid yw'r farn a fynegir gan anfonwr y neges hon o anghenraid yn
adlewyrchu barn Awdurdod Parc Cenedlaethol Bannau Brycheiniog.
Neges yw hon a fwriadwyd ar gyfer y derbynnydd/derbynyddion
yn unig ac fe'i hanfonir yn gyfrinachol; os ydych yn ei dderbyn
mewn camgymeriad, a fyddech gystal â rhoi gwybod i
ni (yn [EMAIL PROTECTED]) ac yna dilëwch bob copi.





Re: GenericDataSource

2001-06-13 Thread Mark Johnson

In Tomcat 3.2.1 the session timeout is set in $JAKARTA_HOME/build/tomcat/conf/web.xml. 
HTH...

 Date: Wed, 13 Jun 2001 14:51:21 +0100
 To: [EMAIL PROTECTED]
 From: Chuck Amadi [EMAIL PROTECTED]
 Subject: Re: GenericDataSource
 Message-ID: [EMAIL PROTECTED]

 Sorry,  anwser to the 1st question , the fact is the session is closed is
 because by default there is a 30 minute time out somewhere in xml doc's
 either tld or struts-config i'll have 2 take a look as im digesting all this
 at work and at home but there is definately a time out period.




Re: GenericDataSource

2001-06-13 Thread Craig R. McClanahan



On Wed, 13 Jun 2001, Mark Johnson wrote:

 In Tomcat 3.2.1 the session timeout is set in
 $JAKARTA_HOME/build/tomcat/conf/web.xml. HTH...
 

Actually, the *default* timeout can be set in your own web.xml file:

  session-config
session-timeout 45 /session-timeout !-- minutes --
  /session-config

Also, at any time, you can change the timeout on a particular session by
calling session.setMaxInactiveInterval().  Thus, you could extend the
timeout when you know that the user might be sitting there for a while,
and shorten it at other times.

Craig McClanahan





Re: GenericDataSource Examples

2001-06-11 Thread David Winterfeldt

I'm not sure if you are asking a more general
question, but this retrieves the Struts connection
pool.

protected Connection getConnection() throws
SQLException {
   DataSource ds =
(DataSource)servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
   return ds.getConnection();
}

  data-sources
data-source
   autoCommit=false
  description=Example Data Source Configuration
  driverClass=sun.jdbc.odbc.JdbcOdbcDriver
 maxCount=4
 minCount=2
 password=
  url=jdbc:odbc:TEST
 user=sa
/
  /data-sources

David


--- hunkpapa [EMAIL PROTECTED] wrote:
 Hi,
 where can I find GenericDataSource Examples ?
 
 


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



RE: GenericDataSource Examples

2001-06-11 Thread Mikkel Bruun

 It in the documentation somewhere...the users guide i believe...

Mikkel

-Original Message-
From: hunkpapa
To: [EMAIL PROTECTED]
Sent: 11-06-2001 21:46
Subject: GenericDataSource Examples

Hi,
where can I find GenericDataSource Examples ?




Re: GenericDataSource error

2001-06-05 Thread Konstantin Priblouda


 Now I've got 
 Begin event threw exception
 java.lang.ClassNotFoundException:
 org/apache/struts/util/GenericDataSource 
 
 when Tomcat tries to compile struts-config.xml
 
 I can see that struts.jar is in the /lib folder and
 GenericDataSource.class
 is there, so what am I missing? Is there something
 else I need to add to my

Maybe you just need to place this class inside a jar
file which resides
in the WEB-INF/lib directory?

AFAIK, assorted classes belong under
WEB-INF/classes



=
Konstantin Priblouda ( ko5tik )Freelance Software developer
 http://www.pribluda.de   play java games - http://www.yook.de 
 render charts online - http://www.pribluda.de/povray/ 

__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



RE: GenericDataSource Reconnection

2001-05-03 Thread Alan Inser

Andre,

Though PoolMan is now version 2.0.1, your code could be interesting. If you
find it again, thanks to put it on this list or send it directly to me at
[EMAIL PROTECTED]

On the other hand, I do not understand why you had to stuck the poolman
instance in the init method, maybe it was related to version 4.1. In the 2.0
Poolman user guide, there is a little section on Struts that tells how to
get the DataSource instance from a static method of PoolMan:
javax.sql.DataSource ds = PoolMan.findDataSource(dbname);

Thanks.
Adriano Labate

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 02, 2001 5:49 PM
To: [EMAIL PROTECTED]
Subject: RE: GenericDataSource Reconnection


i was using PoolMan at first.  i subclassed ActionServlet and just stuck my
poolman instance in one of the init methods.  it worked fine.  i'm just
using
the built in struts pool now because i'm lazy.

if i remember correctly, poolman didn't check each connection before handing
it
out either.  but what it did do was refresh the connections at a
configurable
interval.  i really wanted a check in there to make sure the connection
wasn't
stagnant, so i overrode the validate method in JDBCPool to call a class that
implemented a simple interface called ConnectionTester.   you would could
associate a ConnectionTester class with each db connection in the config
file,
and by default you would just use a dummy ConnectionTester that always
returned
true.  My OracleConnectionTester class just did a select sysdate from dual
and
returned false if a SQLException was thrown.

i believe i still have this code lying around if someone wants to take a
look.
it was in PoolMan1.4.1.

ab

  From:  [EMAIL PROTECTED]
 Date:   05/02/2001 09:44 AM
Please respond to struts-user


Hi,

The difficulty is to find a pretty efficient SQL statement which you want
to
execute each time before returning a connection.
 --- Matthias

As it was already suggested in this forum, the query select dummy from
dual could work well for a Oracle database. For other databases there
would
be specific query strings like the one for Oracle. It could be a property
of
the application.

Is anyone working with PoolMan connection pool instead of the one available
in Struts? Thanks.

Adriano Labate


-Original Message-
From: Matthias Bauer [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 02, 2001 3:59 PM
To: [EMAIL PROTECTED]
Subject: Re: GenericDataSource Reconnection








Re: GenericDataSource Reconnection

2001-05-02 Thread Matthias Bauer

I also had to solve this problem for one of our applications. I changed
GenericDataSource.java, so I am checking the isClosed method of a connection
before I am returning it to the caller of getConnection().

I know, that there is a statement in the Java Specification which says that the
isClosed() method does not need to return the current server state. It just
needs to report whether the close() method has been called before. This is
really unfortunate. But at least the MySQL driver and the PostgesSQL driver
(with a little patch) I am using return the proper server state. So I get along
with my struts patch for these drivers. You will just have to try out if it also
works in your case.

I have included the modified GenericDataSource.java. Try it out and please let
me know whether it works for you.

--- Matthias



Vivek Bhaskaran wrote:
 
 Hi People
 I was looking through the implementation of the javax.sql.DataSource
 (inside the org.apache.struts.util) package. One think I am facing with that
 mysql disconnects after a specified period of timeout. So the DB Pool gets
 corrupted.
 
 I was about to go ahead and add some code to the GenericDataSource to check
 for the conneciton before giving it to a consumer.
 
 Now my question is has this already been done? I did take a look at the
 WebCVS and could not find anything to that repect Is this something that
 needs to be done ?
 
 -vivek
 GenericDataSource.java
 S/MIME Cryptographic Signature


Re: GenericDataSource Reconnection

2001-05-02 Thread Donnie_Hall



I headed down that path too, but then I noticed the GenericConnection class.

The GenericConnection class works with GenericDataSource to override the close
method.  When you call close, it cleans up the connection, set the close flag
to true and returns the connection to the free connection stack.  Therefore,
when you get an available connection from the stack, the IsClosed() method will
alwas return true.  My guess is that your code returns a new connection
everytime you make a database request.  Doing so you quickly head toward your
max connections.  At least that was my experience.

I'm using Oracle and the only way I know how to validate a connection is to
actually make a database call.  So what I was thinking in my own naive way was
to something like this in my code:

boolean sqlSuccess = false;
int sqlAttempts = 0;
while ((!sqlSuccess)  (sqlAttempts  2)) {
   try {
  conn = dataSource.getConnection();
  itemList = ItemLoad.Load(itemId,conn);
  sqlSuccess = true;
}
catch (SQLException e) {
   if (getErrorCode == 28) {// Oracle session killed error code
sqlAttempts++;
conn.remove() // Not a real method, but  would close and remove
from connection pool
   }
   else {
   throw SQLException;
}
 }
}


What do you think?  Has anyone written or planning to write such a method?

Thanks

Donnie Hall



|+-
||  Matthias.Bauer@livi|
||  nglogic.de |
|| |
||  05/02/2001 02:23 AM|
||  Please respond to  |
||  struts-user; Please|
||  respond to |
||  Matthias.Bauer |
|| |
|+-
  |
  ||
  |   To: [EMAIL PROTECTED]   |
  |   cc: (bcc: Donnie Hall/Enron Communications)  |
  |   Subject: Re: GenericDataSource Reconnection  |
  |



I also had to solve this problem for one of our applications. I changed
GenericDataSource.java, so I am checking the isClosed method of a connection
before I am returning it to the caller of getConnection().

I know, that there is a statement in the Java Specification which says that the
isClosed() method does not need to return the current server state. It just
needs to report whether the close() method has been called before. This is
really unfortunate. But at least the MySQL driver and the PostgesSQL driver
(with a little patch) I am using return the proper server state. So I get along
with my struts patch for these drivers. You will just have to try out if it also
works in your case.

I have included the modified GenericDataSource.java. Try it out and please let
me know whether it works for you.

--- Matthias



Vivek Bhaskaran wrote:

 Hi People
 I was looking through the implementation of the javax.sql.DataSource
 (inside the org.apache.struts.util) package. One think I am facing with that
 mysql disconnects after a specified period of timeout. So the DB Pool gets
 corrupted.

 I was about to go ahead and add some code to the GenericDataSource to check
 for the conneciton before giving it to a consumer.

 Now my question is has this already been done? I did take a look at the
 WebCVS and could not find anything to that repect Is this something that
 needs to be done ?

 -vivek(See attached file: GenericDataSource.java)


 GenericDataSource.java


Re: GenericDataSource Reconnection

2001-05-02 Thread Matthias Bauer

 I headed down that path too, but then I noticed the GenericConnection class.
 
 The GenericConnection class works with GenericDataSource to override the close
 method.  When you call close, it cleans up the connection, set the close flag
 to true and returns the connection to the free connection stack.  Therefore,
 when you get an available connection from the stack, the IsClosed() method will
 alwas return true.  My guess is that your code returns a new connection
 everytime you make a database request.  Doing so you quickly head toward your
 max connections.  At least that was my experience.

No! Definitely not! I agree you have to be pretty careful what you do. You
certainly must not call the GenericConnection's isClosed() method. This would
result in what you described - a new connection would always be returned.

You have to call the isClosed() method of the GenericConnection's member conn,
which is of type Connection. Just look at my code, it should be pretty easy to
understand.

 
 I'm using Oracle and the only way I know how to validate a connection is to
 actually make a database call.  So what I was thinking in my own naive way was
 to something like this in my code:
 
 boolean sqlSuccess = false;
 int sqlAttempts = 0;
 while ((!sqlSuccess)  (sqlAttempts  2)) {
try {
   conn = dataSource.getConnection();
   itemList = ItemLoad.Load(itemId,conn);
   sqlSuccess = true;
 }
 catch (SQLException e) {
if (getErrorCode == 28) {// Oracle session killed error code
 sqlAttempts++;
 conn.remove() // Not a real method, but  would close and remove
 from connection pool
}
else {
throw SQLException;
 }
  }
 }
 
 What do you think?  Has anyone written or planning to write such a method?

The difficulty is to find a pretty efficient SQL statement which you want to
execute each time before returning a connection. The clean approach is to let
the driver find out (with any proprietary means that can be used for the
specific database) whether the connection is valid or not. But as I pointed out
earlier, the Java Specification does not request the driver to do that...
unfortunate, isn't it!

 
 Thanks
 
 Donnie Hall

--- Matthias
 S/MIME Cryptographic Signature


RE: GenericDataSource Reconnection

2001-05-02 Thread Alan Inser

Hi,

The difficulty is to find a pretty efficient SQL statement which you want
to
execute each time before returning a connection. 
 --- Matthias

As it was already suggested in this forum, the query select dummy from
dual could work well for a Oracle database. For other databases there would
be specific query strings like the one for Oracle. It could be a property of
the application.

Is anyone working with PoolMan connection pool instead of the one available
in Struts? Thanks.

Adriano Labate


-Original Message-
From: Matthias Bauer [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 02, 2001 3:59 PM
To: [EMAIL PROTECTED]
Subject: Re: GenericDataSource Reconnection





RE: GenericDataSource Reconnection

2001-05-02 Thread Andre_Beskrowni



i was using PoolMan at first.  i subclassed ActionServlet and just stuck my
poolman instance in one of the init methods.  it worked fine.  i'm just using
the built in struts pool now because i'm lazy.

if i remember correctly, poolman didn't check each connection before handing it
out either.  but what it did do was refresh the connections at a configurable
interval.  i really wanted a check in there to make sure the connection wasn't
stagnant, so i overrode the validate method in JDBCPool to call a class that
implemented a simple interface called ConnectionTester.   you would could
associate a ConnectionTester class with each db connection in the config file,
and by default you would just use a dummy ConnectionTester that always returned
true.  My OracleConnectionTester class just did a select sysdate from dual and
returned false if a SQLException was thrown.

i believe i still have this code lying around if someone wants to take a look.
it was in PoolMan1.4.1.

ab

  From:  [EMAIL PROTECTED]
 Date:   05/02/2001 09:44 AM
Please respond to struts-user


Hi,

The difficulty is to find a pretty efficient SQL statement which you want
to
execute each time before returning a connection.
 --- Matthias

As it was already suggested in this forum, the query select dummy from
dual could work well for a Oracle database. For other databases there would
be specific query strings like the one for Oracle. It could be a property of
the application.

Is anyone working with PoolMan connection pool instead of the one available
in Struts? Thanks.

Adriano Labate


-Original Message-
From: Matthias Bauer [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 02, 2001 3:59 PM
To: [EMAIL PROTECTED]
Subject: Re: GenericDataSource Reconnection









RE: GenericDataSource Reconnection

2001-05-02 Thread Anthony Martin

Both methods seem to only check the current connection and move on to the
next one.  What if all of the connections are closed?


Anthony

-Original Message-
From: Alan Inser [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 02, 2001 7:44 AM
To: '[EMAIL PROTECTED]'
Subject: RE: GenericDataSource Reconnection


Hi,

The difficulty is to find a pretty efficient SQL statement which you want
to
execute each time before returning a connection. 
 --- Matthias

As it was already suggested in this forum, the query select dummy from
dual could work well for a Oracle database. For other databases there would
be specific query strings like the one for Oracle. It could be a property of
the application.

Is anyone working with PoolMan connection pool instead of the one available
in Struts? Thanks.

Adriano Labate


-Original Message-
From: Matthias Bauer [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 02, 2001 3:59 PM
To: [EMAIL PROTECTED]
Subject: Re: GenericDataSource Reconnection




Re: GenericDataSource Reconnection

2001-05-02 Thread Donnie_Hall



Sorry, I missed the member call. Unfortunately, I tried it and oracle does not
seem to check the connection status.  It always returns true.

The question becomes:  Do I, (A) test every connection when I get it.  Or, (B)
wait until an exception occurs and then either destory the connection or reset
it.  I lean toward (B), only to avoid an extra loop everytime I call the
database.

Anyone have suggestions or solutions?

Thanks,
Donnie Hall



|+-
||  Matthias.Bauer@livi|
||  nglogic.de |
|| |
||  05/02/2001 08:58 AM|
||  Please respond to  |
||  struts-user; Please|
||  respond to |
||  Matthias.Bauer |
|| |
|+-
  |
  ||
  |   To: [EMAIL PROTECTED]   |
  |   cc: (bcc: Donnie Hall/Enron Communications)  |
  |   Subject: Re: GenericDataSource Reconnection  |
  |



 I headed down that path too, but then I noticed the GenericConnection class.

 The GenericConnection class works with GenericDataSource to override the close
 method.  When you call close, it cleans up the connection, set the close
flag
 to true and returns the connection to the free connection stack.  Therefore,
 when you get an available connection from the stack, the IsClosed() method
will
 alwas return true.  My guess is that your code returns a new connection
 everytime you make a database request.  Doing so you quickly head toward your
 max connections.  At least that was my experience.

No! Definitely not! I agree you have to be pretty careful what you do. You
certainly must not call the GenericConnection's isClosed() method. This would
result in what you described - a new connection would always be returned.

You have to call the isClosed() method of the GenericConnection's member conn,
which is of type Connection. Just look at my code, it should be pretty easy to
understand.


 I'm using Oracle and the only way I know how to validate a connection is to
 actually make a database call.  So what I was thinking in my own naive way was
 to something like this in my code:

 boolean sqlSuccess = false;
 int sqlAttempts = 0;
 while ((!sqlSuccess)  (sqlAttempts  2)) {
try {
   conn = dataSource.getConnection();
   itemList = ItemLoad.Load(itemId,conn);
   sqlSuccess = true;
 }
 catch (SQLException e) {
if (getErrorCode == 28) {// Oracle session killed error code
 sqlAttempts++;
 conn.remove() // Not a real method, but  would close and
remove
 from connection pool
}
else {
throw SQLException;
 }
  }
 }

 What do you think?  Has anyone written or planning to write such a method?

The difficulty is to find a pretty efficient SQL statement which you want to
execute each time before returning a connection. The clean approach is to let
the driver find out (with any proprietary means that can be used for the
specific database) whether the connection is valid or not. But as I pointed out
earlier, the Java Specification does not request the driver to do that...
unfortunate, isn't it!


 Thanks

 Donnie Hall

--- Matthias






RE: GenericDataSource Reconnection

2001-05-01 Thread Anthony Martin

I am facing the same problem.  I use Interbase, and the connection goes down
from time to time for maintenance.  I was trying to build a test case to
present because I was worried I was the only one seeing this problem, in
case it was just my JDBC Driver not reporting it.

Restarting Tomcat is the only workaround I have right now.  This is not my
favorite way to handle it, obviously.  I too would be interested in any
other methods.


Anthony

-Original Message-
From: Vivek Bhaskaran [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 01, 2001 4:18 PM
To: [EMAIL PROTECTED]
Subject: GenericDataSource Reconnection


Hi People
I was looking through the implementation of the javax.sql.DataSource
(inside the org.apache.struts.util) package. One think I am facing with that
mysql disconnects after a specified period of timeout. So the DB Pool gets
corrupted.

I was about to go ahead and add some code to the GenericDataSource to check
for the conneciton before giving it to a consumer.

Now my question is has this already been done? I did take a look at the
WebCVS and could not find anything to that repect Is this something that
needs to be done ?

-vivek



Re: GenericDataSource usage in non-servlet classes

2001-01-26 Thread Johan Compagner

You must have a reference to the servlet or servletcontext somehow.

You could do something like this (you should store the servlet not the session):

protected void process(HttpServletRequest request, HttpServletResponse response)
 throws IOException, ServletException {
 HttpSession session= request.getSession(true);
 SessionHandler.storeCurrentSession(session);
 super.process(request, response);
 SessionHandler.removeCurrentSession();
}

And the SessionHandler is this:

public class SessionHandler 
{
 private static java.util.HashMap _hmSessions = new java.util.HashMap();

public static HttpSession getCurrentSession()
{
 return (HttpSession)_hmSessions.get(Thread.currentThread().getName());
}
public static void removeCurrentSession()
{
 _hmSessions.remove(Thread.currentThread().getName());
}
public static void storeCurrentSession(HttpSession session)
{
 _hmSessions.put(Thread.currentThread().getName(), session);
}
}

Then you can always call SessionHandler.getCurrentSession()
As long as you are in the same thread as the current request, which is very likely

Johan


- Original Message - 
From: "Deping Chian" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, January 23, 2001 2:50 PM
Subject: GenericDataSource usage in non-servlet classes


 Could somebody tell me how to use GenericDataSource in non-servlet classes?
 
 I could access the pool in action servlets using GenericDataSource ds =
 (GenericDataSource)
 servlet.findDataSource(null). But my my non-struts-related classes cannot
 access the pool.
 
 Thanks,
 
 Deping
 
 
 
 




Re: GenericDataSource usage in non-servlet classes

2001-01-23 Thread Craig R. McClanahan

Deping Chian wrote:

 Could somebody tell me how to use GenericDataSource in non-servlet classes?

 I could access the pool in action servlets using GenericDataSource ds =
 (GenericDataSource)
 servlet.findDataSource(null). But my my non-struts-related classes cannot
 access the pool.


If the non-servlet class is part of a Struts-based web application (for
instance, a class called by your Action class), what I normally do is have the
Action do the data source stuff, grab the connection, and then pass on the
connection it received as a parameter to the appropriate method call.  That way,
the non-servlet class would only need to worry about connections, not data
sources.

In a completely non-Struts-based application, you will be responsible for
creating and configuring your own GenericDataSource instance, and then passing
it around or referencing it as a static variable, just like any other Java
object.


 Thanks,

 Deping

Craig McClanahan





Re: GenericDataSource Enhancement

2001-01-08 Thread Johan Compagner

 Except that the javax.sql.DataSource API still includes this method signature, so we 
need to do something.  I guess
 it would probably be better to return a "not implemented" exception of some sort, 
then just return a "regular"
 connection like it does now.

Yes or just a normal connection that the user auto closes when he calls close,
so won't be pooled or anything.

 
  What should be done is testing the isClosed() method before given the Connection 
to the request.
  If the database closes the connection will the connection.isClosed() return a 
boolean true then?
 
 My experience has been that this is not sufficient.  You don't find out that the 
driver connection got closed until
 you try to submit an SQL statement for execution -- what we need to be able to 
configure is a very low-overhead SQL
 call that can be tried before returning the connection to the user.

What about a extra rollback() call right before given it back to the request?
Or is the driver/connection smart enough that the rollback doesn't do anything 
(because nothing happend)
and it doesn't send it to the server?

johan






Re: GenericDataSource Enhancement

2001-01-07 Thread Ted Husted

On 1/6/2001 at 12:26 PM Craig R. McClanahan wrote:
Personally, I've never found the need for the multiple
username/password combinations feature.  I either let my application
manage database access rights, or (on a database like Oracle that
supports them) use database roles to restrict DB privileges -- doing a
SET ROLE command, based on the user I'm doing the current request for,
is pretty fast.

If I understand were we are going with this, we can use more than one
datasource like this 

  data-sources
  data-source
 key="ADMINS"
 autoCommit="true"
description="husted-coreservlets-jdbc"
driverClass="org.gjt.mm.mysql.Driver"
   maxCount="4"
   minCount="2"
   password="xy8592"
url="jdbc:mysql://localhost/test"
   user="webadmin"
  /
 data-source
 key="USERS"
 autoCommit="true"
description="husted-coreservlets-jdbc"
driverClass="org.gjt.mm.mysql.Driver"
   maxCount="400"
   minCount="2"
   password="ab1234"
url="jdbc:mysql://localhost/test"
   user="webuser"
  /
  /data-sources

and then use findDataSource(key) to one or the other. 

And now maybe add a autocloseTimeout type parameter, if we want to
reclaim a large pool of unused connections now and again. (or maybe
just an admin utility we could call on demand, like
admin/dsreclaim.do).

One practical use of this would be to ensure that a block of
administrators can get in, even if the user pool is very busy. 

I haven't tried, but I guess we could also connect to entire different
DBMS's on different computers, if needed.


-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 425-0252; Fax 716 223-2506.
-- http://www.husted.com/





Re: GenericDataSource Enhancement

2001-01-07 Thread Johan Compagner

 I suppose besides adding datasources with different logins, we could
 also add entirely different DBMS's?, on entirely different servers?

Yes that is what the current solution already offers. So the getConnection(String 
user, String pasword)
doesn't have to be implemented, Because if you really need this make another 
datasource under some kind of key.

What should be done is testing the isClosed() method before given the Connection to 
the request.

If the database closes the connection will the connection.isClosed() return a boolean 
true then?

Johan






Re: GenericDataSource Enhancement

2001-01-07 Thread Craig R. McClanahan

Johan Compagner wrote:

  I suppose besides adding datasources with different logins, we could
  also add entirely different DBMS's?, on entirely different servers?

 Yes that is what the current solution already offers. So the getConnection(String 
user, String pasword)
 doesn't have to be implemented, Because if you really need this make another 
datasource under some kind of key.


Except that the javax.sql.DataSource API still includes this method signature, so we 
need to do something.  I guess
it would probably be better to return a "not implemented" exception of some sort, then 
just return a "regular"
connection like it does now.


 What should be done is testing the isClosed() method before given the Connection to 
the request.

 If the database closes the connection will the connection.isClosed() return a 
boolean true then?


My experience has been that this is not sufficient.  You don't find out that the 
driver connection got closed until
you try to submit an SQL statement for execution -- what we need to be able to 
configure is a very low-overhead SQL
call that can be tried before returning the connection to the user.


 Johan

Craig





Re: GenericDataSource Enhancement

2001-01-06 Thread Craig R. McClanahan

Johan Compagner wrote:

  It certainly could, along with other stuff like implementing the
  getConnection(username, password) call correctly.

 How should it work?

 You can't change a current connections username and password (correct me if i am 
wrong)
 So you have to build up a new connection with the supplied username and pasword.

 But what to do when that connections returns?

I would imagine you'd need to maintain a pool of connections for each 
username/password combination that was
requested.  To avoid filling the entire pool with one-off requests, there would 
probably also need to be some sort
of timeout mechanism that released unused ones.


 Should it be pooled for another request for that specifiek username and password?
 or should it be closed right away or don't supply a GenericConnection but a 'normal' 
connection
 so when the users call close() it is really the close of the connection itself 
instead of the GenericConneciton.


Anything or everything is possible, as long as we obey the API contracts.  (In other 
words, it would be legal to not
really "pool" anything, and just create a new connection every time :-).  But it might 
take some experimentation to
see what kinds of functionality are the most useful for apps.

Personally, I've never found the need for the multiple username/password combinations 
feature.  I either let my
application manage database access rights, or (on a database like Oracle that supports 
them) use database roles to
restrict DB privileges -- doing a SET ROLE command, based on the user I'm doing the 
current request for, is pretty
fast.


 Johan

Craig





RE: GenericDataSource Enhancement

2001-01-04 Thread McCay, Larry

My vote would be to hold off until 1.0 is released to add enahancements.

Let's concentrate on the outstanding documentation and any critical bugs.

thanks,

larry

-Original Message-
From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 04, 2001 6:46 PM
To: [EMAIL PROTECTED]
Subject: Re: GenericDataSource Enhancement


David Winterfeldt wrote:

 I don't see GenericDataSource checking to see if a
 connection is dead/closed before it returns it from
 the pool.  I think my ISP shuts down the database at
 night for backups and it kills the connection pool.

 Could checking to see if the connection is live
 (reconect if dead) be added?


It certainly could, along with other stuff like implementing the
getConnection(username, password) call correctly.

Does it need to be fixed within the next few days (i.e. before a 1.0
release),
or are these enhancements we can worry about after 1.0 is released?


 David Winterfeldt


Craig




Re: GenericDataSource Enhancement

2001-01-04 Thread David Winterfeldt

It can wait until after 1.0 is released.  If it could
get fixed in the next couple of weeks, that would be
good.

David Winterfeldt

--- "Craig R. McClanahan"
[EMAIL PROTECTED] wrote:
 David Winterfeldt wrote:
 
  I don't see GenericDataSource checking to see if a
  connection is dead/closed before it returns it
 from
  the pool.  I think my ISP shuts down the database
 at
  night for backups and it kills the connection
 pool.
 
  Could checking to see if the connection is live
  (reconect if dead) be added?
 
 
 It certainly could, along with other stuff like
 implementing the
 getConnection(username, password) call correctly.
 
 Does it need to be fixed within the next few days
 (i.e. before a 1.0 release),
 or are these enhancements we can worry about after
 1.0 is released?
 
 
  David Winterfeldt
 
 
 Craig
 
 


__
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!
http://photos.yahoo.com/