Re: Problems with DBCP in tomcat6

2007-10-08 Thread Josué Alcalde González
El jue, 04-10-2007 a las 05:38 -0400, David Smith escribió:
 Add validationQuery=select 1 to your Resource .../ definition to 
 cause the database pool to test connections and regenerate them as 
 necessary before your code gets a connection.

 --David
 
 
Perfect. It works. That was the solution.
Thank you very much.

 Josué Alcalde González wrote:
  I am having a problem with DBCP.
 
  It is a problem with my applications written last year for
  apache-tomcat-5.5. They worked perfectly but I will soon need
  apache-tomcat-6 and I have upgraded my servers.
 
  I haven't had any problem with my old applications until I discovered
  every morning an exception occurs in my applications related to database
  connection.
 
  It is not a very big problem (connection fails, an error is reported to
  the user, the user tries it again and it works) but it is really
  annoying.
 
  Has something important changed in DBCP which can cause such a problem?
 
  Of course, I suppose you will need more tips to help me.
  As I have said, I use the default datasource and connection pool system
  included with tomcat.
 
  I use to declare my datasource in META-INF/context.xml. For example:
 
 
  ---META-INF/context.xml-
 
  ?xml version=1.0 encoding=UTF-8?
 
  Context debug=5 reloadable=true crossContext=true
 
  Resource name=jdbc/GesdocDB auth=Container
  type=javax.sql.DataSource maxActive=100 maxIdle=30
  maxWait=1000 username=gesdocweb password=***
  driverClassName=com.mysql.jdbc.Driver
  url=jdbc:mysql://127.0.0.1:3306/gesdoc/ 
 
  /Context
 
  ---META-INF/context.xml-
 
 
  I use two different ways to access db in different apps. I have used
  JDBC+common-db-utils and Hibernate and I am having this problem with
  both.
  Since JDBC access is more transparent than Hibernate, I will try to give
  you enough info about how the connection is done.
 
  This would be a tipical conection to database to chek the password of a
  user (sorry, the code is in spanish):
 
  - es.csa.dipu.gesdoc.consultas.ConsultasUsuario -
 
  80 public static User getUsuarioConLogin(String login)  throws
  DataAccessException {
  81   String sql = SELECT idUsuario, login, nombre, apellido1, 
  82   +   apellido2, perfil, cambiarPassword, 
  83   +   password, estado 
  84   + FROM Usuarios WHERE login = ?;;
  85   try {
  86 QueryRunner run = new QueryRunner(DbUtils.getDataSource());
  87 ResultSetHandler h = new BeanHandler(Usuario.class);
  88 return (Usuario) run.query(sql, login, h);
  89   } catch (Exception e) {
  90 log.warn(msg.get(ERROR_CONSULTA_USUARIO), e);
  91 throw new
  DataAccessException(msg.get(ERROR_CONSULTA_USUARIO),e);
  92   }
  93 }
 
  - es.csa.dipu.gesdoc.consultas.ConsultasUsuario -
 
  run.query() will close resultsets, statements and connection and it
  seems the problem is when it tries to close connection. This is a trace
  of the error:
 
  04-oct-2007 8:52:12 es.csa.dipu.gesdoc.consultas.ConsultasUsuario
  getUsuarioConLogin
  ADVERTENCIA: Se ha producido un error al consultar en la tabla usuarios.
  java.sql.SQLException: Already closed.
  at
  org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:84)
  at org.apache.tomcat.dbcp.dbcp.PoolingDataSource
  $PoolGuardConnectionWrapper.close(PoolingDataSource.java:181)
  at org.apache.commons.dbutils.DbUtils.close(DbUtils.java:38)
  at
  org.apache.commons.dbutils.QueryRunner.close(QueryRunner.java:524)
  at
  org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:311)
  at
  org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:285)
  at
  es.csa.dipu.gesdoc.consultas.ConsultasUsuario.getUsuarioConLogin(ConsultasUsuario.java:88)
  at
  es.csa.dipu.gesdoc.beans.LoginBean.doLogin(LoginBean.java:123)
  at sun.reflect.GeneratedMethodAccessor694.invoke(Unknown Source)
  at
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:585)
  at
  org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
  at
  org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
  at javax.faces.component.UICommand.broadcast(UICommand.java:109)
  at
  javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
  at
  javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
  at
  org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
  at
  org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
  at
  

Problems with DBCP in tomcat6

2007-10-04 Thread Josué Alcalde González
I am having a problem with DBCP.

It is a problem with my applications written last year for
apache-tomcat-5.5. They worked perfectly but I will soon need
apache-tomcat-6 and I have upgraded my servers.

I haven't had any problem with my old applications until I discovered
every morning an exception occurs in my applications related to database
connection.

It is not a very big problem (connection fails, an error is reported to
the user, the user tries it again and it works) but it is really
annoying.

Has something important changed in DBCP which can cause such a problem?

Of course, I suppose you will need more tips to help me.
As I have said, I use the default datasource and connection pool system
included with tomcat.

I use to declare my datasource in META-INF/context.xml. For example:


---META-INF/context.xml-

?xml version=1.0 encoding=UTF-8?

Context debug=5 reloadable=true crossContext=true

Resource name=jdbc/GesdocDB auth=Container
type=javax.sql.DataSource maxActive=100 maxIdle=30
maxWait=1000 username=gesdocweb password=***
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/gesdoc/ 

/Context

---META-INF/context.xml-


I use two different ways to access db in different apps. I have used
JDBC+common-db-utils and Hibernate and I am having this problem with
both.
Since JDBC access is more transparent than Hibernate, I will try to give
you enough info about how the connection is done.

This would be a tipical conection to database to chek the password of a
user (sorry, the code is in spanish):

- es.csa.dipu.gesdoc.consultas.ConsultasUsuario -

80 public static User getUsuarioConLogin(String login)  throws
DataAccessException {
81   String sql = SELECT idUsuario, login, nombre, apellido1, 
82   +   apellido2, perfil, cambiarPassword, 
83   +   password, estado 
84   + FROM Usuarios WHERE login = ?;;
85   try {
86 QueryRunner run = new QueryRunner(DbUtils.getDataSource());
87 ResultSetHandler h = new BeanHandler(Usuario.class);
88 return (Usuario) run.query(sql, login, h);
89   } catch (Exception e) {
90 log.warn(msg.get(ERROR_CONSULTA_USUARIO), e);
91 throw new
DataAccessException(msg.get(ERROR_CONSULTA_USUARIO),e);
92   }
93 }

- es.csa.dipu.gesdoc.consultas.ConsultasUsuario -

run.query() will close resultsets, statements and connection and it
seems the problem is when it tries to close connection. This is a trace
of the error:

04-oct-2007 8:52:12 es.csa.dipu.gesdoc.consultas.ConsultasUsuario
getUsuarioConLogin
ADVERTENCIA: Se ha producido un error al consultar en la tabla usuarios.
java.sql.SQLException: Already closed.
at
org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:84)
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource
$PoolGuardConnectionWrapper.close(PoolingDataSource.java:181)
at org.apache.commons.dbutils.DbUtils.close(DbUtils.java:38)
at
org.apache.commons.dbutils.QueryRunner.close(QueryRunner.java:524)
at
org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:311)
at
org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:285)
at
es.csa.dipu.gesdoc.consultas.ConsultasUsuario.getUsuarioConLogin(ConsultasUsuario.java:88)
at
es.csa.dipu.gesdoc.beans.LoginBean.doLogin(LoginBean.java:123)
at sun.reflect.GeneratedMethodAccessor694.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
at
org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
at javax.faces.component.UICommand.broadcast(UICommand.java:109)
at
javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
at
org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
at
org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
at
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
at
javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

Re: Problems with DBCP in tomcat6

2007-10-04 Thread David Smith
Add validationQuery=select 1 to your Resource .../ definition to 
cause the database pool to test connections and regenerate them as 
necessary before your code gets a connection.


--David

Josué Alcalde González wrote:

I am having a problem with DBCP.

It is a problem with my applications written last year for
apache-tomcat-5.5. They worked perfectly but I will soon need
apache-tomcat-6 and I have upgraded my servers.

I haven't had any problem with my old applications until I discovered
every morning an exception occurs in my applications related to database
connection.

It is not a very big problem (connection fails, an error is reported to
the user, the user tries it again and it works) but it is really
annoying.

Has something important changed in DBCP which can cause such a problem?

Of course, I suppose you will need more tips to help me.
As I have said, I use the default datasource and connection pool system
included with tomcat.

I use to declare my datasource in META-INF/context.xml. For example:


---META-INF/context.xml-

?xml version=1.0 encoding=UTF-8?

Context debug=5 reloadable=true crossContext=true

Resource name=jdbc/GesdocDB auth=Container
type=javax.sql.DataSource maxActive=100 maxIdle=30
maxWait=1000 username=gesdocweb password=***
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/gesdoc/ 


/Context

---META-INF/context.xml-


I use two different ways to access db in different apps. I have used
JDBC+common-db-utils and Hibernate and I am having this problem with
both.
Since JDBC access is more transparent than Hibernate, I will try to give
you enough info about how the connection is done.

This would be a tipical conection to database to chek the password of a
user (sorry, the code is in spanish):

- es.csa.dipu.gesdoc.consultas.ConsultasUsuario -

80 public static User getUsuarioConLogin(String login)  throws
DataAccessException {
81   String sql = SELECT idUsuario, login, nombre, apellido1, 
82   +   apellido2, perfil, cambiarPassword, 
83   +   password, estado 
84   + FROM Usuarios WHERE login = ?;;
85   try {
86 QueryRunner run = new QueryRunner(DbUtils.getDataSource());
87 ResultSetHandler h = new BeanHandler(Usuario.class);
88 return (Usuario) run.query(sql, login, h);
89   } catch (Exception e) {
90 log.warn(msg.get(ERROR_CONSULTA_USUARIO), e);
91 throw new
DataAccessException(msg.get(ERROR_CONSULTA_USUARIO),e);
92   }
93 }

- es.csa.dipu.gesdoc.consultas.ConsultasUsuario -

run.query() will close resultsets, statements and connection and it
seems the problem is when it tries to close connection. This is a trace
of the error:

04-oct-2007 8:52:12 es.csa.dipu.gesdoc.consultas.ConsultasUsuario
getUsuarioConLogin
ADVERTENCIA: Se ha producido un error al consultar en la tabla usuarios.
java.sql.SQLException: Already closed.
at
org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:84)
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource
$PoolGuardConnectionWrapper.close(PoolingDataSource.java:181)
at org.apache.commons.dbutils.DbUtils.close(DbUtils.java:38)
at
org.apache.commons.dbutils.QueryRunner.close(QueryRunner.java:524)
at
org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:311)
at
org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:285)
at
es.csa.dipu.gesdoc.consultas.ConsultasUsuario.getUsuarioConLogin(ConsultasUsuario.java:88)
at
es.csa.dipu.gesdoc.beans.LoginBean.doLogin(LoginBean.java:123)
at sun.reflect.GeneratedMethodAccessor694.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
at
org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
at javax.faces.component.UICommand.broadcast(UICommand.java:109)
at
javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
at
org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
at
org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
at
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
at
javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at