Example usage for java.sql Connection isClosed

List of usage examples for java.sql Connection isClosed

Introduction

In this page you can find the example usage for java.sql Connection isClosed.

Prototype

boolean isClosed() throws SQLException;

Source Link

Document

Retrieves whether this Connection object has been closed.

Usage

From source file:com.bisone.saiku.security.replace.SecurityAwareConnectionManager.java

@Override
public void destroy() {
    if (connections != null && !connections.isEmpty()) {
        for (ISaikuConnection con : connections.values()) {
            try {
                Connection c = con.getConnection();
                if (!c.isClosed()) {
                    c.close();//from ww w .j av a2 s .co  m
                }
            } catch (Exception e) {
                log.error("Error destroying connections", e);
            }
        }
    }
    if (connections != null) {
        connections.clear();
    }
}

From source file:bdManager.DBConnectionManager.java

public void closeConnection() throws SQLException {
    long threadID = Thread.currentThread().getId();
    Connection connection = this.connections.get(threadID);

    if (connection != null) {
        if (!connection.isClosed()) {
            connection.close();/*from  www .  ja v  a  2 s  .  c o  m*/
        }
        this.connections.remove(threadID);
    } else {
        throw new SQLException("Session for thread " + threadID + " is not opened.");
    }
}

From source file:pivotal.au.se.gemfirexdweb.controller.RefreshController.java

@RequestMapping(value = "/refresh", method = RequestMethod.GET)
public String showTables(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {

    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*from w w  w  . j  av a2s .  co m*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request refresh schema object list");

    Map schemaMap = (Map) session.getAttribute("schemaMap");
    Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));

    // get schema count now
    schemaMap = QueryUtil.populateSchemaMap(conn, schemaMap, (String) session.getAttribute("schema"));

    session.setAttribute("schemaMap", schemaMap);

    // This will resolve to /WEB-INF/jsp/tables.jsp
    return "main";
}

From source file:com.microsoft.sqlserver.jdbc.connection.PoolingTest.java

@Test
public void testConnectionPoolClose() throws SQLException {
    SQLServerXADataSource ds = new SQLServerXADataSource();
    ds.setURL(connectionString);//from w  w  w . j a v  a 2 s  .  c  o m

    PooledConnection pc = ds.getPooledConnection();
    Connection con = pc.getConnection();

    pc.close();
    // assert that the first connection is closed.
    assertTrue(con.isClosed(), "Connection is not closed with pool close");
}

From source file:org.saiku.plugin.PentahoSecurityAwareConnectionManager.java

@Override
public void destroy() {
    if (connections != null && !connections.isEmpty()) {
        for (ISaikuConnection con : connections.values()) {
            try {
                Connection c = con.getConnection();
                if (!c.isClosed()) {
                    c.close();//from   www  .  j a v a  2  s  .co  m
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    connections.clear();
}

From source file:org.apache.ddlutils.platform.ModelBasedResultSetIterator.java

/**
 * Determines whether the connection is still open.
 * /*from   w w  w  .j av  a2s .co  m*/
 * @return <code>true</code> if the connection is still open
 */
public boolean isConnectionOpen() {
    if (_resultSet == null) {
        return false;
    }
    try {
        Statement stmt = _resultSet.getStatement();
        Connection conn = stmt.getConnection();

        return !conn.isClosed();
    } catch (SQLException ex) {
        return false;
    }
}

From source file:pivotal.au.se.gemfirexdweb.controller.HistoryController.java

@RequestMapping(value = "/history", method = RequestMethod.GET)
public String showHistory(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from  ww  w.  j av a 2s.  c  o  m
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to show command history");
    UserPref userPref = (UserPref) session.getAttribute("prefs");

    String histAction = request.getParameter("histAction");

    if (histAction != null) {
        logger.debug("histAction = " + histAction);
        // clear history
        session.setAttribute("history", new LinkedList());

        model.addAttribute("historyremoved", "Succesfully cleared history list");
    }

    LinkedList historyList = (LinkedList) session.getAttribute("history");

    int maxsize = userPref.getHistorySize();

    model.addAttribute("historyList", historyList.toArray());
    model.addAttribute("historysize", historyList.size());

    // This will resolve to /WEB-INF/jsp/history.jsp
    return "history";
}

From source file:pivotal.au.se.gemfirexdweb.controller.ConmapController.java

@RequestMapping(value = "/viewconmap", method = RequestMethod.GET)
public String worksheet(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/* w w  w .j a v a  2  s .c  o  m*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to show connection map");

    ConnectionManager cm = ConnectionManager.getInstance();

    String conMapAction = request.getParameter("conMapAction");
    String key = request.getParameter("key");

    logger.debug("conMapAction = " + conMapAction);
    logger.debug("key = " + key);

    if (conMapAction != null) {
        if (conMapAction.equalsIgnoreCase("DELETE")) {
            // remove this connection from Map and close it.
            cm.removeConnection(key);
            logger.debug("Connection closed for key " + key);
            model.addAttribute("saved", "Successfully closed connection with key " + key);
        }
    }

    model.addAttribute("conmap", cm.getConnectionMap());
    model.addAttribute("conmapsize", cm.getConnectionListSize());

    // This will resolve to /WEB-INF/jsp/conmap.jsp
    return "conmap";
}

From source file:ch.astina.hesperid.installer.web.services.InstallationManager.java

public void testDatabaseConnection(String databaseUrl, String databaseUser, String databaseSecret)
        throws Exception {
    Connection con = null;

    try {/* ww  w. ja  v  a  2 s.  c  o  m*/
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        con = DriverManager.getConnection(databaseUrl, databaseUser, databaseSecret);

        if (!con.isClosed()) {
            logger.info("Successfully connected to " + "MySQL server using TCP/IP...");
        }
    } catch (Exception e) {
        throw e;
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (Exception ex) {
                logger.error("Error while closing connection");
            }
        }
    }
}

From source file:org.atricore.idbus.idojos.dbidentitystore.AbstractDBIdentityStore.java

/**
 * Close the given db connection./*from ww w  . j a  va2 s . c om*/
 *
 * @param dbConnection
 * @throws SSOIdentityException
 */
protected void closeDBConnection(Connection dbConnection) throws SSOIdentityException {

    try {
        if (dbConnection != null && !dbConnection.isClosed()) {
            try {
                dbConnection.commit();
            } catch (SQLException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Error while committing connection");
                }
                try {
                    dbConnection.rollback();
                } catch (SQLException e1) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Error while rollback connection");
                    }
                }
            }
        }
        if (dbConnection != null && !dbConnection.isClosed()) {
            dbConnection.close();
        }
    } catch (SQLException se) {
        if (logger.isDebugEnabled()) {
            logger.debug("Error while clossing connection");
        }

        throw new SSOIdentityException("Error while clossing connection\n" + se.getMessage());
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Error while clossing connection");
        }

        throw new SSOIdentityException("Error while clossing connection\n" + e.getMessage());

    }

}