List of usage examples for org.apache.commons.dbutils DbUtils closeQuietly
public static void closeQuietly(Statement stmt)
Statement
, avoid closing if null and hide any SQLExceptions that occur. From source file:com.splicemachine.derby.test.framework.SpliceFunctionWatcher.java
@Override protected void starting(Description description) { LOG.trace("Starting"); Connection connection = null; Statement statement = null;//from ww w . j a v a 2s .c o m ResultSet rs = null; try { connection = (userName == null) ? SpliceNetConnection.getConnection() : SpliceNetConnection.getConnectionAs(userName, password); rs = connection.getMetaData().getTables(null, schemaName, functionName, null); if (rs.next()) { executeDrop(schemaName, functionName); } connection.commit(); statement = connection.createStatement(); statement.execute(CREATE_FUNCTION + schemaName + "." + functionName + " " + createString); connection.commit(); } catch (Exception e) { LOG.error("Create function statement is invalid "); e.printStackTrace(); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } super.starting(description); }
From source file:com.intelligentz.appointmentz.controllers.addR.java
@Override public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { try {// w ww.jav a 2s.c om String room_number = req.getParameter("room_number"); String hospital_id = req.getParameter("hospital_id"); connection = DBConnection.getDBConnection().getConnection(); String SQL12 = "select room_number from room where room_number=? and hospital_id=?"; preparedStmt = connection.prepareStatement(SQL12); preparedStmt.setString(1, room_number); preparedStmt.setString(2, hospital_id); // execute the preparedstatement resultSet = preparedStmt.executeQuery(); if (resultSet.next()) { res.sendRedirect( "./addRoom.jsp?status=This Room Number Already Available!&room_number=" + room_number); return; } String SQL1 = "insert into room ( hospital_id, room_number) VALUES (?,?)"; preparedStmt = connection.prepareStatement(SQL1); preparedStmt.setString(1, hospital_id); preparedStmt.setString(2, room_number); // execute the preparedstatement preparedStmt.execute(); res.sendRedirect("./home?status=Room successfully added!"); } catch (SQLException | PropertyVetoException ex) { LOGGER.log(Level.SEVERE, null, ex); res.sendRedirect("./error.jsp?error=Error in adding 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:azkaban.db.DatabaseOperatorImpl.java
/** * transaction method Implementation.//w w w .j ava 2s . c o m * */ @Override public <T> T transaction(SQLTransaction<T> operations) throws SQLException { Connection conn = null; try { conn = queryRunner.getDataSource().getConnection(); conn.setAutoCommit(false); DatabaseTransOperator transOperator = new DatabaseTransOperatorImpl(queryRunner, conn); T res = operations.execute(transOperator); conn.commit(); return res; } catch (SQLException ex) { // todo kunkun-tang: Retry logics should be implemented here. logger.error("transaction failed", ex); throw ex; } finally { DbUtils.closeQuietly(conn); } }
From source file:ca.qc.adinfo.rouge.variable.db.PersistentVariableDb.java
public static Variable getPersitentVariable(DBManager dbManager, String key) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;/*from w ww.j a v a 2s .co m*/ String sql = "SELECT value, version FROM rouge_persistant_variable WHERE `key` = ?"; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, key); rs = stmt.executeQuery(); if (rs.next()) { JSONObject jSonObject = JSONObject.fromObject(rs.getString("value")); return new Variable(key, new RougeObject(jSonObject), rs.getLong("version")); } else { return null; } } catch (SQLException e) { log.error(e); return null; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:com.uiip.gviviani.esercizioweekend.interfaces.impl.DefaultPhoneDAO.java
@Override public boolean inserisciPhone(PhoneModel phone) { MysqlDataSource datasource = new MysqlDataSource(); datasource.setUser("root"); datasource.setPassword("root"); datasource.setUrl("jdbc:mysql://localhost:3306/Rubrica"); Connection connection = null; try {/*from w w w.j av a 2 s .c om*/ connection = datasource.getConnection(); String sql = "INSERT INTO telefono (name, brand, opsys, displaySize) VALUE " + "(?, ?, ?, ?);"; PreparedStatement stat = connection.prepareStatement(sql); stat.setString(1, phone.getNome()); stat.setString(2, phone.getBrand()); stat.setString(3, phone.getOpsys()); stat.setString(4, phone.getDisplay()); if (stat.executeUpdate() > 0) { return true; } } catch (SQLException e) { logger.error(e); } finally { DbUtils.closeQuietly(connection); } return false; }
From source file:framework.retrieval.engine.index.all.database.impl.rdAbstract.DefaultRDatabaseIndexAllImpl.java
/** * ? * @param conn */ private void close(Connection conn) { DbUtils.closeQuietly(conn); }
From source file:ca.qc.adinfo.rouge.mail.db.MailDb.java
public static boolean deleteMail(DBManager dbManager, long mailId) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;// ww w . j a va 2 s. c o m String sql = null; sql = "UPDATE rouge_mail SET `status` = ? WHERE `id` = ? "; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, "del"); stmt.setLong(2, mailId); int ret = stmt.executeUpdate(); return (ret > 0); } catch (SQLException e) { log.error(stmt); log.error(e); return false; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:net.big_oh.common.jdbc.JdbcProxyExerciser.java
private static void exerciseBatchInsert(Connection con) throws SQLException { logger.info(StringUtils.center("exercise batch insert", 100, "-")); Statement stmt = null;/* ww w .j a va 2 s. c o m*/ try { stmt = con.createStatement(); stmt.addBatch("INSERT INTO TEST_TABLE VALUES ( 'value2' )"); stmt.addBatch("INSERT INTO TEST_TABLE VALUES ( 'value3' )"); stmt.executeBatch(); } finally { DbUtils.closeQuietly(stmt); } }
From source file:com.splicemachine.derby.test.framework.SpliceViewWatcher.java
public static void executeDrop(String schemaName, String viewName) { LOG.trace("executeDrop"); Connection connection = null; Statement statement = null;/*from ww w . j a v a2 s. c o m*/ try { connection = SpliceNetConnection.getConnection(); statement = connection.createStatement(); statement.execute("drop view " + schemaName.toUpperCase() + "." + viewName.toUpperCase()); connection.commit(); } catch (Exception e) { LOG.error("error Dropping " + e.getMessage()); e.printStackTrace(System.err); throw new RuntimeException(e); } finally { DbUtils.closeQuietly(statement); DbUtils.commitAndCloseQuietly(connection); } }
From source file:com.gs.obevo.db.impl.platforms.AbstractSqlExecutor.java
@Override public <T> T executeWithinContext(PhysicalSchema schema, ThrowingFunction<Connection, T> callable) { Connection conn = null;//from w w w. j a v a 2 s .c o m try { conn = ds.getConnection(); setDataSourceSchema(conn, schema); return callable.safeValueOf(conn); } catch (Exception e) { throw new DeployerRuntimeException(e); } finally { DbUtils.closeQuietly(conn); } }