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:jp.co.golorp.emarf.sql.MetaData.java
/** * ??mysql??/* w w w. j a va2s . c om*/ * * @param cn * ? * @param tableName * ?? * @return */ private static String getTableCommentByShowTableStatus(final Connection cn, final String tableName) { ResultSet rs = null; try { rs = cn.createStatement().executeQuery("show table status where name = '" + tableName + "'"); if (rs.next()) { commentSource = TableCommentSources.showTableStatus; return rs.getString("COMMENT"); } } catch (SQLException e) { } finally { DbUtils.closeQuietly(rs); } return null; }
From source file:com.che.software.testato.domain.dao.jdbc.impl.IterationDAO.java
/** * Retrieves the remaining scripts count for a given prioritization. * //from ww w.j a v a 2s . c o m * @author Clement HELIOU (clement.heliou@che-software.com). * @param prioritization the given prioritization. * @return the resulting count. * @since July, 2011. * @throws IterationSearchDAOException if an error occurs during the search. */ @Override public int getRemainingScriptsCountFromPrioritization(Prioritization prioritization) throws IterationSearchDAOException { LOGGER.debug("getRemainingScriptsCountFromPrioritization(" + prioritization.getPrioritizationId() + ")."); Connection connection = null; try { connection = getDataSource().getConnection(); return (Integer) getQueryRunner().query(connection, "SELECT COALESCE(((MAX(depth)-MIN(depth))+1),0)::int AS result FROM script WHERE hierarchy_id = ? AND NOT EXISTS( SELECT iteration_assignment_id FROM comparisonMatrixItem WHERE first_script = script_id ) ", new ScalarHandler("result"), new Object[] { prioritization.getHierarchyId() }); } catch (SQLException e) { throw new IterationSearchDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:com.splicemachine.derby.utils.SpliceAdminIT.java
@Test public void testGetActiveServers() throws Exception { CallableStatement cs = methodWatcher.prepareCall("call SYSCS_UTIL.SYSCS_GET_ACTIVE_SERVERS()"); ResultSet rs = cs.executeQuery(); TestUtils.FormattedResult fr = TestUtils.FormattedResult.ResultFactory .convert("call SYSCS_UTIL.SYSCS_GET_ACTIVE_SERVERS()", rs); System.out.println(fr.toString()); Assert.assertTrue(fr.size() >= 1); DbUtils.closeQuietly(rs); }
From source file:com.intelligentz.appointmentz.controllers.Data.java
public static String checkSerialAuth(String serial, String auth) { String check = "default"; String SQL = ""; try {/*from ww w . j a va2 s .c o m*/ connection = DBConnection.getDBConnection().getConnection(); SQL = "select serial from rpi where serial = ? or auth = ?"; preparedStatement = connection.prepareStatement(SQL); preparedStatement.setString(1, serial); preparedStatement.setString(2, auth); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { check = "Available"; } else { check = "Unavailable"; } } catch (SQLException | IOException | PropertyVetoException e) { check = "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 check; }
From source file:io.personium.diff.App.java
/** * ???./*from w w w .j a v a 2 s .c om*/ */ public void execute() { EsClient client = new EsClient(clusterName, clusterHosts); Connection conn = getMySqlConnection(); try { List<String> excludeUnitUser = listExcludeUnitUser(indexPrefix, excludeFilePath); List<String> indexNames = listEsIndices(client, indexPrefix, unitUser, excludeUnitUser); List<String> databases = listMySQLDatabases(conn, indexPrefix, unitUser, excludeUnitUser); if (!isIndexAndDatabaseMatched(indexNames, databases)) { log.warn("Index and database is not matched."); return; } if (indexNames.isEmpty() && databases.isEmpty()) { log.info("UnitUser is nothing"); return; } checkMasterConsistency(client, conn, databases); clearWorkTable(conn); if (unitUser == null && excludeFilePath != null) { checkDavResourceConsistency(client, conn, indexNames); } else { checkDavResourceConsistency(client, conn, indexNames, unitUser); } } finally { DbUtils.closeQuietly(conn); client.closeConnection(); } }
From source file:com.akman.excel.view.frmSelectImage.java
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSaveActionPerformed {//GEN-HEADEREND:event_btnSaveActionPerformed Connection conn = null;//w ww . ja v a 2 s.c om conn = Javaconnect.ConnecrDb(); try { // String sql = "INSERT INTO ExcelData (Image) VALUES (?)"; String sql = "Update ExcelData SET Image = ? WHERE Id = 1"; pst = conn.prepareStatement(sql); pst.setBytes(1, person_image); pst.execute(); System.out.println(person_image); JOptionPane.showMessageDialog(null, "Update Image"); getImage(); } catch (SQLException ex) { Logger.getLogger(frmSelectImage.class.getName()).log(Level.SEVERE, null, ex); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(pst); DbUtils.closeQuietly(conn); } }
From source file:com.mirth.connect.server.migration.ServerMigrator.java
/** * Builds the database schema on the connected database if it does not exist * //w ww.j a va 2 s. c o m * @throws MigrationException */ private void initDatabase(Connection connection) throws MigrationException { // If missing this table we can assume that they don't have the schema installed if (!DatabaseUtil.tableExists(connection, "CONFIGURATION")) { executeScript("/" + getDatabaseType() + "/" + getDatabaseType() + "-database.sql"); /* * We must update the password date for the initial user. Previously we let the database * set this via CURRENT_TIMESTAMP, however this could create problems if the database is * running on a separate machine in a different timezone. (MIRTH-2902) */ PreparedStatement statement = null; try { statement = getConnection().prepareStatement("UPDATE PERSON_PASSWORD SET PASSWORD_DATE = ?"); statement.setTimestamp(1, new Timestamp(System.currentTimeMillis())); statement.executeUpdate(); } catch (SQLException e) { throw new MigrationException(e); } finally { DbUtils.closeQuietly(statement); } updateVersion(Version.getLatest()); } }
From source file:com.che.software.testato.domain.dao.jdbc.impl.ScriptDAO.java
/** * Updates a script from his object.//from w w w.j a v a 2 s. c om * * @author Clement HELIOU (clement.heliou@che-software.com). * @param scriptToUpdate the script object to update in the database. * @since August, 2011. * @throws ScriptUpdateDAOException if an error occurs during the update. */ @Override public void updateScript(Script scriptToUpdate) throws ScriptUpdateDAOException { LOGGER.debug("updateScript()."); Connection connection = null; try { connection = getDataSource().getConnection(); List<Object> params = new ArrayList<Object>(); getQueryRunner().update(connection, getScriptUpdateQueryFromCriterion(scriptToUpdate, params), params.toArray()); } catch (SQLException e) { throw new ScriptUpdateDAOException(e); } finally { if (null != connection) { DbUtils.closeQuietly(connection); } } }
From source file:jp.co.golorp.emarf.sql.MetaData.java
/** * ??oracle??// w ww. ja v a 2s .c o m * * @param cn * ? * @param tableName * ?? * @return */ private static String getTableCommentByUserTabComments(final Connection cn, final String tableName) { ResultSet rs = null; try { String sql = "SELECT * FROM USER_TAB_COMMENTS WHERE TABLE_NAME = '" + tableName + "'"; rs = cn.createStatement().executeQuery(sql); if (rs.next()) { commentSource = TableCommentSources.userTabComments; return rs.getString("COMMENTS"); } } catch (SQLException e) { } finally { DbUtils.closeQuietly(rs); } return null; }
From source file:azkaban.trigger.JdbcTriggerLoader.java
private Connection getConnection() throws TriggerLoaderException { Connection connection = null; try {//from w w w . ja v a 2s .com connection = super.getDBConnection(false); } catch (Exception e) { DbUtils.closeQuietly(connection); throw new TriggerLoaderException("Error getting DB connection.", e); } return connection; }