List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:fi.ilmoeuro.membertrack.db.DataIntegrityException.java
public static @Nullable DataIntegrityException fromThrowable(Throwable throwable) { Throwable rootCause = ExceptionUtils.getRootCause(throwable); if (rootCause instanceof SQLException) { SQLException sqle = (SQLException) rootCause; String constraint = ""; String message = sqle.getMessage(); if (message != null) { Matcher matcher = CONSTRAINT_REGEX.matcher(message); if (matcher.find()) { String group = matcher.group(1); if (group != null) { constraint = group;//w w w. ja va 2 s . c om } } } for (IntegrityViolation errorType : IntegrityViolation.values()) { if (errorType.errorCodes.contains(sqle.getSQLState())) { return new DataIntegrityException(errorType, constraint, throwable); } } } return null; }
From source file:com.wso2telco.dao.TransactionDAO.java
/** * Insert transaction log.//from w w w .j a v a 2 s. c om * * @param transaction the transaction * @param contextId the context id * @param statusCode the status code * @throws Exception the exception */ public static void insertTransactionLog(Transaction transaction, String contextId, int statusCode) throws Exception { Connection conn = null; PreparedStatement ps = null; try { conn = DbUtil.getConnectDBConnection(); String query = "INSERT INTO mcx_cross_operator_transaction_log (tx_id, tx_status, batch_id, api_id, " + "client_id," + " application_state, sub_op_mcc, sub_op_mnc, timestamp_start, timestamp_end, " + "exchange_response_code)" + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; ps = conn.prepareStatement(query); ps.setString(1, transaction.getTx_id()); ps.setString(2, transaction.getTx_status()); ps.setString(3, contextId); ps.setString(4, transaction.getApi().getId()); ps.setString(5, transaction.getClient_id()); ps.setString(6, transaction.getApplication_state()); ps.setString(7, transaction.getSubscriber_operator().getMcc()); ps.setString(8, transaction.getSubscriber_operator().getMnc()); ps.setString(9, transaction.getTimestamp().getStart()); ps.setString(10, transaction.getTimestamp().getEnd()); ps.setInt(11, statusCode); ps.execute(); } catch (SQLException e) { handleException("Error in inserting transaction log record : " + e.getMessage(), e); } finally { DbUtil.closeAllConnections(ps, conn, null); } }
From source file:fr.paris.lutece.plugins.updater.util.sql.SqlUtils.java
/** * Executes an SQL script// w w w.j a va 2 s. com * @param strScript An SQL script * @param plugin The plugin * @throws SQLException If an SQL exception occurs */ public static void executeSqlScript(String strScript, Plugin plugin) throws SQLException { String strCleanScript = strScript.substring(0, strScript.lastIndexOf(";")); StringTokenizer st = new StringTokenizer(strCleanScript, ";"); Transaction transaction = new Transaction(); try { while (st.hasMoreTokens()) { String strSQL = st.nextToken(); transaction.prepareStatement(strSQL); transaction.executeStatement(); } transaction.commit(); } catch (SQLException ex) { transaction.rollback(ex); AppLogService.error("Execute SQL script error : " + ex.getMessage() + " - transaction rolled back.", ex); throw ex; } }
From source file:jongo.handler.JongoResultSetHandler.java
/** * Converts a ResultSet to a Map. Important to note that DATE, TIMESTAMP & TIME objects generate * a {@linkplain org.joda.time.DateTime} object using {@linkplain org.joda.time.format.ISODateTimeFormat}. * @param resultSet a {@linkplain java.sql.ResultSet} * @return a Map with the column names as keys and the values. null if something goes wrong. *///from ww w .ja v a2 s. com public static Map<String, String> resultSetToMap(ResultSet resultSet) { Map<String, String> map = new HashMap<String, String>(); try { int columnCount = resultSet.getMetaData().getColumnCount(); l.trace("Mapping a result set with " + columnCount + " columns to a Map"); ResultSetMetaData meta = resultSet.getMetaData(); for (int i = 1; i < columnCount + 1; i++) { String colName = meta.getColumnName(i).toLowerCase(); int colType = meta.getColumnType(i); String v = resultSet.getString(i); if (colType == Types.DATE) { v = new DateTime(resultSet.getDate(i)).toString(dateFTR); l.trace("Mapped DATE column " + colName + " with value : " + v); } else if (colType == Types.TIMESTAMP) { v = new DateTime(resultSet.getTimestamp(i)).toString(dateTimeFTR); l.trace("Mapped TIMESTAMP column " + colName + " with value : " + v); } else if (colType == Types.TIME) { v = new DateTime(resultSet.getTimestamp(i)).toString(timeFTR); l.trace("Mapped TIME column " + colName + " with value : " + v); } else { l.trace("Mapped " + meta.getColumnTypeName(i) + " column " + colName + " with value : " + v); } map.put(colName, v); } } catch (SQLException e) { l.error("Failed to map ResultSet"); l.error(e.getMessage()); return null; } return map; }
From source file:OCCIConnectionServlet.java
protected static synchronized void checkIn(Connection c) { try {// ww w . j a v a2 s . c om c.close(); } catch (SQLException e) { System.err.println(e.getMessage() + " closing connection"); } }
From source file:com.ibm.soatf.tool.Utils.java
public static String getSQLExceptionMessage(SQLException ex) { return String.format("SQL Code: %s Message: %s", ex.getErrorCode(), ex.getMessage()); }
From source file:com.splout.db.engine.JDBCManager.java
protected static EngineException convertException(SQLException e) { if (e instanceof SQLSyntaxErrorException) { return new EngineManager.SyntaxErrorException(e.getMessage()); } else if (e instanceof SQLTimeoutException) { return new EngineManager.QueryInterruptedException(e.getMessage()); } else {//from w ww .j a v a 2 s . co m return new EngineManager.ShouldNotRetryInReplicaException(e.getMessage(), e); } }
From source file:br.gov.jfrj.siga.persistencia.oracle.JDBCUtilOracle.java
public static Connection getConnection(final String url, final String usuario, final String credencial) { Connection conn = null;/*from ww w .java 2s. c om*/ try { conn = DriverManager.getConnection(url, usuario, credencial); } catch (final SQLException e) { JDBCUtilOracle.log.debug(Messages.getString("Oracle.SQLErro")); System.err.print(Messages.getString("Oracle.SQLErro") + e.getMessage()); } return conn; }
From source file:com.sun.portal.os.portlets.PortletChartUtilities.java
private static JDBCXYDataset generateXYDataSet(Connection con, String sql) { JDBCXYDataset data = null;// w ww. j av a2s . c om try { data = new JDBCXYDataset(con); data.executeQuery(sql); con.close(); } catch (SQLException e) { System.err.print("SQLException: "); System.err.println(e.getMessage()); } catch (Exception e) { System.err.print("Exception: "); System.err.println(e.getMessage()); } return data; }
From source file:com.sun.portal.os.portlets.PortletChartUtilities.java
private static JDBCCategoryDataset generateBarChartDataSet(Connection con, String sql) { JDBCCategoryDataset data = null;//w ww.j ava2 s.com try { data = new JDBCCategoryDataset(con); data.executeQuery(sql); con.close(); } catch (SQLException e) { System.err.print("SQLException: "); System.err.println(e.getMessage()); } catch (Exception e) { System.err.print("Exception: "); System.err.println(e.getMessage()); } return data; }