Java Code Examples for javax.sql.ConnectionEvent#getSQLException()

The following examples show how to use javax.sql.ConnectionEvent#getSQLException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyedCPDSConnectionFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    if (null != event.getSQLException()) {
        System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
    }
    pc.removeConnectionEventListener(this);

    final PooledConnectionAndInfo info = pcMap.get(pc);
    if (info == null) {
        throw new IllegalStateException(NO_KEY_MESSAGE);
    }
    try {
        pool.invalidateObject(info.getUserPassKey(), info);
    } catch (final Exception e) {
        System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + info);
        e.printStackTrace();
    }
}
 
Example 2
Source File: CPDSConnectionFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    if (null != event.getSQLException()) {
        System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
    }
    pc.removeConnectionEventListener(this);

    final PooledConnectionAndInfo pci = pcMap.get(pc);
    if (pci == null) {
        throw new IllegalStateException(NO_KEY_MESSAGE);
    }
    try {
        pool.invalidateObject(pci);
    } catch (final Exception e) {
        System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
        e.printStackTrace();
    }
}
 
Example 3
Source File: KeyedCPDSConnectionFactory.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    if (null != event.getSQLException()) {
        System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
    }
    pc.removeConnectionEventListener(this);

    final PooledConnectionAndInfo info = pcMap.get(pc);
    if (info == null) {
        throw new IllegalStateException(NO_KEY_MESSAGE);
    }
    try {
        pool.invalidateObject(info.getUserPassKey(), info);
    } catch (final Exception e) {
        System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + info);
        e.printStackTrace();
    }
}
 
Example 4
Source File: CPDSConnectionFactory.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    if (null != event.getSQLException()) {
        System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
    }
    pc.removeConnectionEventListener(this);

    final PooledConnectionAndInfo pci = pcMap.get(pc);
    if (pci == null) {
        throw new IllegalStateException(NO_KEY_MESSAGE);
    }
    try {
        pool.invalidateObject(pci);
    } catch (final Exception e) {
        System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
        e.printStackTrace();
    }
}
 
Example 5
Source File: XAConnectionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void connectionClosed(ConnectionEvent event) {
	Iterator<ConnectionEventListener> itr = this.connectionEventListeners.iterator();
	while (itr.hasNext()) {
		ConnectionEventListener listener = itr.next();
		SQLException sqlException = event.getSQLException();
		ConnectionEvent connectionEvent = new ConnectionEvent(this, sqlException);
		try {
			listener.connectionClosed(connectionEvent);
		} catch (RuntimeException error) {
			logger.warn("Error occurred!", error);
		}
	} // end-while (itr.hasNext())
}
 
Example 6
Source File: XAConnectionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void connectionErrorOccurred(ConnectionEvent event) {
	Iterator<ConnectionEventListener> itr = this.connectionEventListeners.iterator();
	while (itr.hasNext()) {
		ConnectionEventListener listener = itr.next();
		SQLException sqlException = event.getSQLException();
		ConnectionEvent connectionEvent = new ConnectionEvent(this, sqlException);
		try {
			listener.connectionErrorOccurred(connectionEvent);
		} catch (RuntimeException error) {
			logger.warn("Error occurred!", error);
		}
	} // end-while (itr.hasNext())
}
 
Example 7
Source File: MyEventListener.java    From mariadb-connector-j with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void connectionClosed(ConnectionEvent event) {
  sqlException = event.getSQLException();
  closed = true;
}
 
Example 8
Source File: MyEventListener.java    From mariadb-connector-j with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void connectionErrorOccurred(ConnectionEvent event) {
  sqlException = event.getSQLException();
  connectionErrorOccured = true;
}