Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

SQLContainer - communication link failure after few hours of inactivity

Daniela Maratta
10 years ago Feb 29, 2012 9:25pm
Freek Uijtdewilligen
9 years ago Mar 18, 2013 2:34pm
Matthew Keller
8 years ago Oct 28, 2013 6:17pm
Henri Sara
8 years ago Oct 29, 2013 6:47am
Carlo Ottolina
8 years ago Oct 29, 2013 10:48am

This happens when the back end closes connections on time out.

You need to validate the connection with something like this:

public final boolean isValid(final Connection con) throws SQLException {
        final String bogusQuery = "SELECT 1";

        try (Statement st = con.createStatement(); ResultSet res = st.executeQuery(bogusQuery)) {
            return true;
        } catch (final SQLException sqlx) {
            return false;
        }
    }

in

Connection#reserveConnection()
Connection c;
        do {
            if (this.availableConnections.isEmpty()) {
                if (this.reservedConnections.size() < this.maxConnections) {
                    this.availableConnections.add(this.createConnection());
                } else {
                    throw new SQLException("Connection limit has been reached.");
                }
            }

            c = this.availableConnections.iterator().next();
            if (c == null) {
                throw new SQLException("Bad connection pool.");
            }
            if (!this.isValid(c)) {
                try {
                    c.close();
                    this.availableConnections.remove(c);
                    c = null;
                } catch (final SQLException e1) {
                    /* Nothing needs to be done */
                }
            } else {
                break;
            }
        } while (c == null);

Cheers.

Dino Fancellu
8 years ago Oct 29, 2013 7:13pm
Pere Pasqual
4 years ago Aug 04, 2017 8:12am
Pere Pasqual
4 years ago Aug 04, 2017 9:01am
Carlo Ottolina
4 years ago Aug 08, 2017 2:09pm
Pere Pasqual
4 years ago Nov 08, 2017 10:41am
Jan Scheer
4 years ago Nov 13, 2017 11:51am
Pere Pasqual
4 years ago Nov 13, 2017 11:58am
Pere Pasqual
3 years ago Apr 17, 2018 2:03pm