List of usage examples for java.sql SQLException fillInStackTrace
public synchronized Throwable fillInStackTrace()
From source file:org.gsoft.admin.ScriptRunner.java
/** * Runs an SQL script (read in using the Reader parameter) using the * connection passed in/*from w ww . jav a2 s . c o m*/ * * @param conn * - the connection to use for the script * @param reader * - the source of the script * @throws SQLException * if any SQL errors occur * @throws IOException * if there is an error reading from the Reader */ private void runScript(Connection conn, Reader reader) throws IOException, SQLException { StringBuffer command = null; try { LineNumberReader lineReader = new LineNumberReader(reader); String line = null; while ((line = lineReader.readLine()) != null) { if (command == null) { command = new StringBuffer(); } String trimmedLine = line.trim(); if (trimmedLine.startsWith("--")) { println(trimmedLine); } else if (trimmedLine.length() < 1 || trimmedLine.startsWith("//")) { // Do nothing } else if (trimmedLine.length() < 1 || trimmedLine.startsWith("--")) { // Do nothing } else if (!fullLineDelimiter && trimmedLine.endsWith(getDelimiter()) || fullLineDelimiter && trimmedLine.equals(getDelimiter())) { command.append(line.substring(0, line.lastIndexOf(getDelimiter()))); command.append(" "); Statement statement = conn.createStatement(); println(command); boolean hasResults = false; if (stopOnError) { hasResults = statement.execute(command.toString()); } else { try { statement.execute(command.toString()); } catch (SQLException e) { e.fillInStackTrace(); printlnError("Error executing: " + command); printlnError(e); } } if (autoCommit && !conn.getAutoCommit()) { conn.commit(); } ResultSet rs = statement.getResultSet(); if (hasResults && rs != null) { ResultSetMetaData md = rs.getMetaData(); int cols = md.getColumnCount(); for (int i = 0; i < cols; i++) { String name = md.getColumnLabel(i); print(name + "\t"); } println(""); while (rs.next()) { for (int i = 0; i < cols; i++) { String value = rs.getString(i); print(value + "\t"); } println(""); } } command = null; try { statement.close(); } catch (Exception e) { // Ignore to workaround a bug in Jakarta DBCP } Thread.yield(); } else { command.append(line); command.append(" "); } } if (!autoCommit) { conn.commit(); } } catch (SQLException e) { e.fillInStackTrace(); printlnError("Error executing: " + command); printlnError(e); throw e; } catch (IOException e) { e.fillInStackTrace(); printlnError("Error executing: " + command); printlnError(e); throw e; } finally { conn.rollback(); flush(); } }
From source file:com.tesora.dve.worker.Worker.java
public void resetStatement(CompletionHandle<Boolean> promise) throws SQLException { CompletionHandle<Boolean> resultTracker = new DelegatingCompletionHandle<Boolean>(promise) { @Override/*from ww w . ja va 2s .c om*/ public void success(Boolean returnValue) { super.success(returnValue); } @Override public void failure(Exception e) { if (e instanceof SQLException) super.failure(e); SQLException problem = new SQLException("Unable to reset worker connection", e); problem.fillInStackTrace(); super.failure(problem); } }; if (!StringUtils.isEmpty(currentGlobalTransaction)) { try { rollback(currentGlobalTransaction, resultTracker); // currentGlobalTransaction = null; } catch (Exception e) { SQLException problem = new SQLException("Unable to reset worker connection", e); problem.fillInStackTrace(); promise.failure(problem); return; } } else { promise.success(true); } }
From source file:gov.utah.dts.sdc.dao.BaseDAO.java
public Object getBaseObject(String statementName, Object parameterObject) throws DaoException { Object result = null;/* www .j a v a2s .c o m*/ try { try { sqlMap.startTransaction(); result = sqlMap.queryForObject(statementName, parameterObject); sqlMap.commitTransaction(); } finally { sqlMap.endTransaction(); } } catch (SQLException e) { log.error(e); throw new DaoException(e.fillInStackTrace()); } return result; }
From source file:gov.utah.dts.sdc.dao.BaseDAO.java
public List getBaseList(String statementName, Object parameterObject) throws DaoException { List list = null;//from w ww. j av a2s . co m try { try { sqlMap.startTransaction(); list = sqlMap.queryForList(statementName, parameterObject); sqlMap.commitTransaction(); } finally { sqlMap.endTransaction(); } } catch (SQLException ex) { log.error(ex); throw new DaoException(ex.fillInStackTrace()); } return list; }
From source file:gov.utah.dts.sdc.dao.BaseDAO.java
public int baseDelete(String statementName, Object parameterObject) throws DaoException { int result = 0; try {/*from w w w . j a v a2 s . c o m*/ try { sqlMap.startTransaction(); result = sqlMap.delete(statementName, parameterObject); sqlMap.commitTransaction(); } finally { sqlMap.endTransaction(); } } catch (SQLException e) { log.error(e); throw new DaoException(e.fillInStackTrace()); } // Redmine 4318, 30821 (enhancements) - ALM logging. try { if (userId != null) { HashMap hm = null; if (parameterObject instanceof HashMap) { hm = (HashMap) parameterObject; } else { hm = getFormData(parameterObject); } if (isAlmLog((String) hm.get("almLog"), statementName)) { almLog(statementName, "RD", hm); } } } catch (Exception e) { // ignore the error, yet send a notification email. log.error("** Error in ALM log Web service!" + e.getMessage()); try { sendALMErrorEmail(e.getMessage()); } catch (Exception e2) { log.error("Error of sending confirmation email for ALM Error."); } } return result; }
From source file:gov.utah.dts.sdc.dao.BaseDAO.java
public int baseUpdate(String statementName, Object parameterObject) throws DaoException { log.debug("baseUpdate"); int result = 0; try {/*from ww w . ja v a2s . c om*/ try { sqlMap.startTransaction(); result = sqlMap.update(statementName, parameterObject); sqlMap.commitTransaction(); } finally { sqlMap.endTransaction(); } } catch (SQLException e) { log.error(e); throw new DaoException(e.fillInStackTrace()); } // Redmine 4318, 30821 (enhancements) - ALM logging. try { if (userId != null) { HashMap hm = null; if (parameterObject instanceof HashMap) { hm = (HashMap) parameterObject; } else { hm = getFormData(parameterObject); } if (isAlmLog((String) hm.get("almLog"), statementName)) { almLog(statementName, "RE", hm); } } } catch (Exception e) { // ignore the error, yet send a notification email. log.error("** Error in ALM log Web service!" + e.getMessage()); try { sendALMErrorEmail(e.getMessage()); } catch (Exception e2) { log.error("Error of sending confirmation email for ALM Error."); } } return result; }
From source file:nl.b3p.viewer.util.databaseupdate.ScriptRunner.java
/** * Runs an SQL script (read in using the Reader parameter) using the * connection passed in//from w w w . ja v a2s .c om * * @param conn - the connection to use for the script * @param reader - the source of the script * @throws SQLException if any SQL errors occur * @throws IOException if there is an error reading from the Reader */ private void runScript(Connection conn, Reader reader) throws IOException, SQLException { StringBuffer command = null; try { LineNumberReader lineReader = new LineNumberReader(reader); String line = null; while ((line = lineReader.readLine()) != null) { if (command == null) { command = new StringBuffer(); } String trimmedLine = line.trim(); if (trimmedLine.startsWith("--")) { log.debug(trimmedLine); } else if (trimmedLine.length() < 1 || trimmedLine.startsWith("//")) { // Do nothing } else if (trimmedLine.length() < 1 || trimmedLine.startsWith("--")) { // Do nothing } else if (!fullLineDelimiter && trimmedLine.endsWith(getDelimiter()) || fullLineDelimiter && trimmedLine.equals(getDelimiter())) { command.append(line.substring(0, line.lastIndexOf(getDelimiter()))); command.append(" "); Statement statement = conn.createStatement(); log.debug(command); boolean hasResults = false; if (stopOnError) { hasResults = statement.execute(command.toString()); } else { try { statement.execute(command.toString()); } catch (SQLException e) { e.fillInStackTrace(); log.error("Error executing: " + command, e); } } if (autoCommit && !conn.getAutoCommit()) { conn.commit(); } ResultSet rs = statement.getResultSet(); if (hasResults && rs != null) { ResultSetMetaData md = rs.getMetaData(); int cols = md.getColumnCount(); for (int i = 0; i < cols; i++) { String name = md.getColumnLabel(i); log.debug(name + "\t"); } while (rs.next()) { for (int i = 0; i < cols; i++) { String value = rs.getString(i); log.debug(value + "\t"); } } } command = null; try { statement.close(); } catch (Exception e) { // Ignore to workaround a bug in Jakarta DBCP } Thread.yield(); } else { command.append(line); command.append(" "); } } if (!autoCommit) { conn.commit(); } } catch (SQLException e) { e.fillInStackTrace(); log.error("Error executing: " + command, e); throw e; } catch (IOException e) { e.fillInStackTrace(); log.error("Error executing: " + command, e); throw e; } finally { if (!this.autoCommit) { conn.rollback(); } } }
From source file:uk.nhs.cfh.dsp.snomed.converters.xml.utils.SnomedConceptDBUtils.java
/** * Gets the fully specified name.//from w ww .j av a2 s . c o m * * @param connection the connection * @param conceptID the concept id * @return the fully specified name */ public static String getFullySpecifiedName(Connection connection, String conceptID) { String fullySpecifiedName = ""; try { PreparedStatement getFullySpecifiedNameStatement = connection.prepareStatement( "" + "SELECT FULLYSPECIFIEDNAME FROM SNOMED.CONCEPT " + "WHERE CONCEPTID = ? "); getFullySpecifiedNameStatement.setString(1, conceptID); ResultSet rs = getFullySpecifiedNameStatement.executeQuery(); while (rs.next()) { // render in piped format fullySpecifiedName = conceptID + " |" + rs.getString("FULLYSPECIFIEDNAME") + "|"; } // close statement and result set rs.close(); getFullySpecifiedNameStatement.close(); } catch (SQLException e) { logger.warn(e.fillInStackTrace()); } return fullySpecifiedName; }
From source file:uk.nhs.cfh.dsp.snomed.converters.xml.utils.SnomedConceptDBUtils.java
/** * Gets the all concept i ds./*from w w w . java 2 s . c o m*/ * * @param connection the connection * @return the all concept i ds */ public static Set<String> getAllConceptIDs(Connection connection) { Set<String> conceptIDs = new HashSet<String>(); try { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery("" + "SELECT CONCEPTID FROM SNOMED.CONCEPT"); while (rs.next()) { String conceptID = rs.getString("CONCEPTID"); // add to set conceptIDs.add(conceptID); } } catch (SQLException e) { logger.warn(e.fillInStackTrace()); } return conceptIDs; }
From source file:uk.nhs.cfh.dsp.snomed.dao.impl.SnomedConceptDatabaseDAO.java
/** * Instantiates a new snomed concept database dao. * * @param dataSource the data source// ww w. j a va2s .c om */ public SnomedConceptDatabaseDAO(DataSource dataSource) { if (dataSource != null) { try { this.connection = dataSource.getConnection(); initialiseStatements(); } catch (SQLException e) { logger.warn("Error obtaining connection from data source. " + "Nested exception is : " + e.fillInStackTrace()); } } }