Example usage for org.apache.commons.dbutils DbUtils close

List of usage examples for org.apache.commons.dbutils DbUtils close

Introduction

In this page you can find the example usage for org.apache.commons.dbutils DbUtils close.

Prototype

public static void close(Statement stmt) throws SQLException 

Source Link

Document

Close a Statement, avoid closing if null.

Usage

From source file:com.neu.edu.DAO.DAO.java

public void close(Connection connection) {
    if (connection != null) {
        try {//  w w  w  .  j a  va 2  s. c  o  m
            DbUtils.close(connection);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
}

From source file:com.me.DAO.DAO1.java

public void close(Connection connection) {
    if (connection != null) {
        try {//from  w  w w  . j  ava 2  s .  co  m
            DbUtils.close(connection);
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
    }
}

From source file:com.intelligentz.appointmentz.controllers.Data.java

public static String getRooms(String hospital_id) {
    String rooms = "";
    try {/*from ww w  .j ava2  s .c  o m*/

        connection = DBConnection.getDBConnection().getConnection();
        //String SQL = "select room_number,room_id from room where hospital_id = ?";
        String SQL = "select room_number,room_id from room where hospital_id = ?";
        preparedStatement = connection.prepareStatement(SQL);
        preparedStatement.setString(1, hospital_id);
        resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            String room_number = resultSet.getString("room_number");
            String room_id = resultSet.getString("room_id");
            //String room_id = resultSet.getString("room_id");
            rooms += "<option value=\"" + room_id + "\">" + room_number + "</option>";
        }

    } catch (SQLException | IOException | PropertyVetoException e) {
        //throw new IllegalStateException
        rooms = "Error";
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStatement);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
    return rooms;
}

From source file:com.mmone.hsqldb.Database.java

public void shutDown() throws SQLException {
    if (conn != null) {
        qr.update("SHUTDOWN");
        DbUtils.close(conn);
    } else {/*w ww  .j  av  a2 s .  c  om*/
        System.out.println("conn alredy closed");
    }

}

From source file:com.intelligentz.appointmentz.controllers.deleteRPI.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    try {//ww  w .j  a  va 2 s . co  m
        String serial = req.getParameter("serial");
        connection = DBConnection.getDBConnection().getConnection();
        String SQL1 = "delete from rpi where serial=?";
        preparedStmt = connection.prepareStatement(SQL1);
        preparedStmt.setString(1, serial);
        // execute the preparedstatement
        preparedStmt.execute();
        res.sendRedirect("./equipments?status=Successfully Deleted Device Serial:" + serial);
    } catch (SQLException | PropertyVetoException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
        res.sendRedirect("./error.jsp?error=Error in delettiing device!\n+" + ex.toString() + "");
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStmt);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
}

From source file:com.fyp.conflictanalysistestmav.controller.GraphController.java

public static ArrayList<Node> getSuccessors(Node node) {

    ArrayList<Node> successorList = new ArrayList<>();
    try {//from w  w w  .  j  a v  a2  s.c  o m
        connection = DBConnection.getDBConnection().getConnection();
        String SQL1 = "SELECT category_id, category_name FROM successor natural join category "
                + "where graph_category_id = ? and " + "category.category_id = successor.successor_id;";

        preparedStatement = connection.prepareStatement(SQL1);
        preparedStatement.setString(1, node.getGraph_category_id());

        resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            Node successor = new Node();
            successor.setId(resultSet.getString("category_id"));
            successor.setName(resultSet.getString("category_name"));
            successor.setType(NodeTypes.NODE_TYPE_CATEGORY);
            successorList.add(successor);
        }

    } catch (SQLException | IOException | PropertyVetoException ex) {
        LOGGER.log(Level.SEVERE, ex.toString(), ex);
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStatement);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            LOGGER.log(Level.SEVERE, ex.toString(), ex);
        }
    }

    return successorList;
}

From source file:com.intelligentz.appointmentz.controllers.deleteRoom.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    try {/*from w  w w.  jav a2 s.  c o  m*/
        String room_id = req.getParameter("room_id");
        String room_number = req.getParameter("room_number");
        String hospital_id = req.getParameter("hospital_id");
        connection = DBConnection.getDBConnection().getConnection();
        String SQL1 = "delete from room where room_id = ?";
        preparedStmt = connection.prepareStatement(SQL1);
        preparedStmt.setString(1, room_id);
        // execute the preparedstatement
        preparedStmt.execute();
        res.sendRedirect(
                "./equipments?status=Successfully Deleted Room_number:" + room_number + " Room_id:" + room_id);
    } catch (SQLException | PropertyVetoException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
        res.sendRedirect("./error.jsp?error=Error in deletting room!\n+" + ex.toString() + "");
    } finally {
        try {
            //DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStmt);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
}

From source file:com.intelligentz.appointmentz.controllers.editBerry.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    try {//from www. j ava  2  s  .com
        String room_id = req.getParameter("room_id");
        //String room_number = req.getParameter("room_number");
        String auth = req.getParameter("auth_hidden");
        String serial = req.getParameter("serial_hidden");
        connection = DBConnection.getDBConnection().getConnection();
        String SQL1 = "update rpi set room_id = ? where serial= ?";
        preparedStmt = connection.prepareStatement(SQL1);
        preparedStmt.setString(1, room_id);
        preparedStmt.setString(2, serial);
        // execute the preparedstatement
        preparedStmt.execute();
        res.sendRedirect("./equipments?status=Successfully Updated Device Details Serial:" + serial
                + " -> Room_id:" + room_id);
    } catch (SQLException | PropertyVetoException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
        res.sendRedirect("./error.jsp?error=Error in adding device!\n+" + ex.toString() + "");
    } finally {
        try {
            // DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStmt);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
}

From source file:net.orpiske.ssps.common.db.version.DbVersionDao.java

/**
 * Creates the tables /*ww  w  . ja  v a  2s .c  om*/
 * @throws java.sql.SQLException if unable to create the table
 */
public void createTable() throws SQLException {
    DatabaseManager databaseManager = getDatabaseManager();
    Connection conn = databaseManager.getConnection();

    String query = queries.get("createTable");

    Statement s = null;

    try {
        s = conn.createStatement();
        s.execute(query);
    } finally {
        DbUtils.close(s);
    }
}

From source file:com.intelligentz.appointmentz.controllers.Data.java

public static String getRooms(String hospital_id, String room_id_default) {
    String rooms = "";
    try {//from   w  ww .j  av  a2 s.  co  m

        connection = DBConnection.getDBConnection().getConnection();
        //String SQL = "select room_number,room_id from room where hospital_id = ?";
        String SQL = "select room_number,room_id from room where hospital_id = ?";
        preparedStatement = connection.prepareStatement(SQL);
        preparedStatement.setString(1, hospital_id);
        resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            String room_number = resultSet.getString("room_number");
            String room_id = resultSet.getString("room_id");
            if (room_id_default.equals(room_id))
                rooms += "<option selected=\"selected\" value=\"" + room_id + "\">" + room_number + "</option>";
            else
                rooms += "<option value=\"" + room_id + "\">" + room_number + "</option>";
        }

    } catch (SQLException | IOException | PropertyVetoException e) {
        //throw new IllegalStateException
        rooms = "Error";
    } finally {
        try {
            DbUtils.closeQuietly(resultSet);
            DbUtils.closeQuietly(preparedStatement);
            DbUtils.close(connection);
        } catch (SQLException ex) {
            Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex);
        }
    }
    return rooms;
}