You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Princeton Lau <pl...@wei.org> on 2001/09/12 19:14:49 UTC

RE: DataSource timeouts? A possible solution for Oracle 8.1.7

Hello all,

Has anyone addressed this?  I tried setting the pingQuery command to 'select
dummy from dual', but the GenericDataSource still did not pick up that the
connection it had was stale...

My solution is a work around.  I would have liked to continue using the
Struts connection pool, but it just did not work very well with frequently
dropping DB connections.

The connection it provides may be stale and invalid, but the URL, username,
and password are still good.  So in my code, I simply took those attributes
and used them in my own datasource.  I used Oracle's own pooled connection
datasource, it recovers fine from dropped DB connections.  With the new
datasource, I could again create reliable connections by taking connections
from the connection pool.

I understand this approach is not ideal, but in light of the
GenericDataSource not working in my situation, it is usable.

Anyone have a better solution?  

This is the code I used...

Action.java
.
.
.
javax.sql.DataSource dataSource = servlet.findDataSource("DB");
      GenericDataSource ds = (GenericDataSource) dataSource;
      model.setCon(ds.getUrl());

Model.java
.
.
.
  public void setCon(String url) throws SQLException{

      OracleDataSource ods = new OracleDataSource();

      // Set the user name, password, driver type and network protocol
      ods.setURL(url);

      // Retrieve a connection
      con = ods.getConnection();

      con.setAutoCommit(false);
  }

RE: DataSource timeouts?

----------------------------------------------------------------------------
----

From: VASQUEZ_JASON 
Subject: RE: DataSource timeouts? 
Date: Fri, 03 Aug 2001 04:58:56 -0700 

----------------------------------------------------------------------------
----

I understand that--my app does "close" connections (release back to the 
pool).  The problem is that the pool itself maintains open connections to 
the database, and doesn't seem to recover very well when the databsae dies 
and comes back.

-jason

Satyen.Chikane@ing-barings.com
08/02/2001 11:31 AM
Please respond to struts-user

 
        To:     struts-user@jakarta.apache.org
        cc: 
        Subject:        RE: DataSource timeouts?



in the documentation it says that you close the connection after you have
used it...
ie.
conn.close();
this wont close the connection but will release it for others to use...


-----Original Message-----
From: VASQUEZ_JASON@LILLY.COM [mailto:VASQUEZ_JASON@LILLY.COM]
Sent: Thursday, August 02, 2001 5:07 PM
To: struts-user@jakarta.apache.org
Subject: DataSource timeouts?


Is there any parameter that can be set to timeout datasources, or to 
re-init them after a specified period of time?  We recently bounced our 
Oracle database that our struts connection pool points to, and I noticed 
that all the connections had hung (the app just hung while trying to 
perform queries).  The only way to fix it (that I knew of) was to restart 
the servlet container.  Is there a better way around this?

Thnaks,
Jason


Re: DataSource timeouts? A possible solution for Oracle 8.1.7

Posted by Ted Husted <hu...@apache.org>.
Why is using Oracle's pooled connection datasource not ideal?

The GenericDataSource class can be handy, but it is expected that
developers will often use something else. 

Personally, I use Poolman by CodeStudio. 

I'd say the best approach is to have a helper class that returns the
connection, so that the rest of your application doesn't know where it
comes from. The reason I use Poolman is because the Struts Datasource is
exposed through the ServletContext, and I didn't want to bind my helper
to HTTP.

Here's what I use to get a connection. I can just change this one class
to change pools. 

public final class ConnectionPool {
    /**
     * An exception message to throw if datasource is null.
     */
    public static final String DATASOURCE_ERROR = "Connection pool " +
        "not available. Check your poolman.xml config, and be sure " +
        " you are using a valid dbname parameter (use dbname, not
jndiName)";
    /**
     * The application scope attribute under which our JNDI datasource
     * is stored.
     */
    public static final String JNDI_DATASOURCE_KEY = "articles";
    /**
     * Returns a JDBC connection from a connection pool or other
     * resource, to be used and closed promptly.
     * <p>
     * @returns JDBC connection from resource layer.
     * @exception SQLException on SQL or other errors. May wrap other
     * exceptions depending on implementation. Will not return null.
     */
    public static final Connection getConnection() throws SQLException {
        DataSource ds = PoolMan.findDataSource(JNDI_DATASOURCE_KEY);
        if (ds==null)
            throw new SQLException(DATASOURCE_ERROR);
        return(ds.getConnection());
    }
}

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/about/struts/

Princeton Lau wrote:
> 
> Hello all,
> 
> Has anyone addressed this?  I tried setting the pingQuery command to 'select
> dummy from dual', but the GenericDataSource still did not pick up that the
> connection it had was stale...
> 
> My solution is a work around.  I would have liked to continue using the
> Struts connection pool, but it just did not work very well with frequently
> dropping DB connections.
> 
> The connection it provides may be stale and invalid, but the URL, username,
> and password are still good.  So in my code, I simply took those attributes
> and used them in my own datasource.  I used Oracle's own pooled connection
> datasource, it recovers fine from dropped DB connections.  With the new
> datasource, I could again create reliable connections by taking connections
> from the connection pool.
> 
> I understand this approach is not ideal, but in light of the
> GenericDataSource not working in my situation, it is usable.
> 
> Anyone have a better solution?
> 
> This is the code I used...
> 
> Action.java
> .
> .
> .
> javax.sql.DataSource dataSource = servlet.findDataSource("DB");
>       GenericDataSource ds = (GenericDataSource) dataSource;
>       model.setCon(ds.getUrl());
> 
> Model.java
> .
> .
> .
>   public void setCon(String url) throws SQLException{
> 
>       OracleDataSource ods = new OracleDataSource();
> 
>       // Set the user name, password, driver type and network protocol
>       ods.setURL(url);
> 
>       // Retrieve a connection
>       con = ods.getConnection();
> 
>       con.setAutoCommit(false);
>   }
> 
> RE: DataSource timeouts?
> 
> ----------------------------------------------------------------------------
> ----
> 
> From: VASQUEZ_JASON
> Subject: RE: DataSource timeouts?
> Date: Fri, 03 Aug 2001 04:58:56 -0700
> 
> ----------------------------------------------------------------------------
> ----
> 
> I understand that--my app does "close" connections (release back to the
> pool).  The problem is that the pool itself maintains open connections to
> the database, and doesn't seem to recover very well when the databsae dies
> and comes back.
> 
> -jason
> 
> Satyen.Chikane@ing-barings.com
> 08/02/2001 11:31 AM
> Please respond to struts-user
> 
> 
>         To:     struts-user@jakarta.apache.org
>         cc:
>         Subject:        RE: DataSource timeouts?
> 
> in the documentation it says that you close the connection after you have
> used it...
> ie.
> conn.close();
> this wont close the connection but will release it for others to use...
> 
> -----Original Message-----
> From: VASQUEZ_JASON@LILLY.COM [mailto:VASQUEZ_JASON@LILLY.COM]
> Sent: Thursday, August 02, 2001 5:07 PM
> To: struts-user@jakarta.apache.org
> Subject: DataSource timeouts?
> 
> Is there any parameter that can be set to timeout datasources, or to
> re-init them after a specified period of time?  We recently bounced our
> Oracle database that our struts connection pool points to, and I noticed
> that all the connections had hung (the app just hung while trying to
> perform queries).  The only way to fix it (that I knew of) was to restart
> the servlet container.  Is there a better way around this?
> 
> Thnaks,
> Jason