What happens to JBoss if I restart the database?
You can configure the following in your -ds.xml
<valid-connection-checker-class-name>[see [jboss]/docs/examples/jca/[mydb]-ds.xml]</valid-connection-checker-class-name>
JBoss will use the jdbc drivers ping operation to check the connection. If the ping fails the connection will be destroyed/closed and new ones will be created. The valid-connection-checker-class-name must implement the following ValidConnectionChecker interface:
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.resource.adapter.jdbc;
import java.sql.Connection;
import java.sql.SQLException;
/**
* Checks that a connection is valid
*
* @author <a href="mailto:adrian@jboss.org">Adrian Brock</a>
* @version $Revision: 1.3.4.1 $
*/
public interface ValidConnectionChecker
{
/**
* Checks the connection is valid
*
* @param c the connection
* @return Exception when not valid, null when valid
*/
SQLException isValidConnection(Connection c);
}
OR you can use:
<check-valid-connection-sql>some cheap sql statement</check-valid-connection-sql> e.g. for Oracle "select 1 from dual"
JBoss will run the SQL statement before handing out the connection from the pool. If the SQL fails, the connection will be destroyed/closed and new ones will be created.
<check-valid-connection> SQL for Sybase:
If you are using
select @@VERSION
with Sybase, then it may not always work. See this for details http://community.jboss.org/thread/156667?tstart=0
Comments