List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:com.netradius.hibernate.support.HibernateUtil.java
private static List<String[]> getColumns(final String table) { final List<String[]> rows = new ArrayList<String[]>(); rows.add(new String[] { "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION", "IS_NULLABLE", "SCOPE_CATLOG", "SCOPE_SCHEMA", "SCOPE_TABLE", "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT" }); Connection con = null;/*from w w w . j a v a 2 s. com*/ ResultSet rs = null; try { con = getConnection(); final DatabaseMetaData md = con.getMetaData(); rs = md.getColumns(null, null, table, "%"); while (rs.next()) { List<String> s = new ArrayList<String>(23); for (int i = 23; i > 0; i--) s.add(rs.getString(i)); rows.add(s.toArray(new String[23])); } } catch (SQLException x) { log.error("Error describing table: " + x.getMessage(), x); } finally { close(con, null, rs); } return rows; }
From source file:com.netradius.hibernate.support.HibernateUtil.java
/** * Utilitiy method to close JDBC connections, statements and result sets. * * @param con the connection to close or null * @param stmt the statement to close or null * @param rs the result set to close or null *//* ww w .java2s .c o m*/ public static void close(Connection con, Statement stmt, ResultSet rs) { if (rs != null) { try { rs.close(); } catch (SQLException x) { log.error("Error closing result set: " + x.getMessage(), x); } } if (stmt != null) { try { con.close(); } catch (SQLException x) { log.error("Error closing statement: " + x.getMessage(), x); } } if (con != null) { try { con.close(); } catch (SQLException x) { log.error("Error closing connection: " + x.getMessage(), x); } } }
From source file:io.cloudslang.content.database.utils.SQLUtils.java
/** * Some databases (Sybase) throw exceptions during a database restore. This function processes that exception, and if it is that type, builds up the output of the command * * @param e The exception to analyze// w w w.jav a2s . com * @return The output of the dump command * @throws java.sql.SQLException If it was not a successful load command's exception. */ public static String processLoadException(SQLException e) throws SQLException { final String sqlState = e.getSQLState(); if (sqlState != null && StringUtils.equalsIgnoreCase(sqlState, "s1000")) { SQLException f = e; StringBuilder s = new StringBuilder(); s.append(f.getMessage()); while ((f = f.getNextException()) != null) s.append("\n").append(f.getMessage()); String str = s.toString(); if (StringUtils.containsIgnoreCase(str, "load is complete")) return str; } throw e; }
From source file:net.pms.database.TableThumbnails.java
/** * Attempts to find a thumbnail in this table by MD5 hash. If not found, * it writes the new thumbnail to this table. * Finally, it writes the ID from this table as the THUMBID in the FILES * table./* w ww . ja va2 s . c om*/ * * @param thumbnail * @param fullPathToFile */ public static void setThumbnail(final DLNAThumbnail thumbnail, final String fullPathToFile) { String query; String md5Hash = DigestUtils.md5Hex(thumbnail.getBytes(false)); try (Connection connection = database.getConnection()) { query = "SELECT * FROM " + TABLE_NAME + " WHERE MD5 = " + sqlQuote(md5Hash) + " LIMIT 1"; LOGGER.trace("Searching for thumbnail in {} with \"{}\" before update", TABLE_NAME, query); TABLE_LOCK.writeLock().lock(); try (PreparedStatement statement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, Statement.RETURN_GENERATED_KEYS)) { connection.setAutoCommit(false); try (ResultSet result = statement.executeQuery()) { if (result.next()) { LOGGER.trace( "Found existing file entry with ID {} in {}, setting the THUMBID in the FILES table", result.getInt("ID"), TABLE_NAME); // Write the existing thumbnail ID to the FILES table PMS.get().getDatabase().updateThumbnailId(fullPathToFile, result.getInt("ID")); } else { LOGGER.trace("File entry \"{}\" not found in {}", md5Hash, TABLE_NAME); result.moveToInsertRow(); result.updateString("MD5", md5Hash); result.updateObject("THUMBNAIL", thumbnail); result.updateTimestamp("MODIFIED", new Timestamp(System.currentTimeMillis())); result.insertRow(); try (ResultSet generatedKeys = statement.getGeneratedKeys()) { if (generatedKeys.next()) { // Write the new thumbnail ID to the FILES table LOGGER.trace( "Inserting new thumbnail with ID {}, setting the THUMBID in the FILES table", generatedKeys.getInt(1)); PMS.get().getDatabase().updateThumbnailId(fullPathToFile, generatedKeys.getInt(1)); } } } } finally { connection.commit(); } } finally { TABLE_LOCK.writeLock().unlock(); } } catch (SQLException e) { LOGGER.error("Database error while writing \"{}\" to {}: {}", md5Hash, TABLE_NAME, e.getMessage()); LOGGER.trace("", e); } }
From source file:jongo.demo.Demo.java
private static void destroyDemoDatabase(final DatabaseConfiguration dbcfg) { final String database = dbcfg.getDatabase(); QueryRunner run = new QueryRunner(JDBCConnectionFactory.getDataSource(dbcfg)); l.info("Destroying Demo Tables in database " + database); try {//from www . ja v a2s .c om run.update("DROP FUNCTION simpleStoredProcedure"); run.update("DROP PROCEDURE insert_comment"); run.update("DROP PROCEDURE get_year_sales"); run.update("DROP VIEW MAKER_STATS_2010"); run.update("DROP TABLE maker_stats"); run.update("DROP TABLE sales_stats"); run.update("DROP TABLE comments"); run.update("DROP TABLE pictures"); run.update("DROP TABLE car"); run.update("DROP TABLE users"); run.update("DROP TABLE maker"); run.update("DROP TABLE empty"); } catch (SQLException ex) { l.error("Failed to destroy demo tables " + ex.getMessage()); } finally { try { run.getDataSource().getConnection().close(); } catch (SQLException ex) { l.error("Failed to close demo database " + ex.getMessage()); } } }
From source file:Emporium.Controle.ContrVpne.java
public static boolean inserirVpne(String sql, String nomeBD) { Connection conn = Conexao.conectar(nomeBD); try {//from w w w .java 2s. co m PreparedStatement valores = conn.prepareStatement(sql); valores.executeUpdate(); valores.close(); return true; } catch (SQLException e) { Logger.getLogger(ContrPreVendaImporta.class.getName()).log(Level.WARNING, e.getMessage(), e); return false; } finally { Conexao.desconectar(conn); } }
From source file:info.extensiblecatalog.OAIToolkit.db.DButil.java
private static void logException(SQLException sqlex, String sql) { prglog.error("[PRG] SQLException with " + "SQLState='" + sqlex.getSQLState() + "' and " + "errorCode=" + sqlex.getErrorCode() + " and " + "message=" + sqlex.getMessage() + "; sql was '" + sql + "'" + " open/total: " + connectionCounter + "/" + connectionCounterTotal); }
From source file:com.wso2telco.mnc.resolver.mncrange.McnRangeDbUtil.java
/** * Close connection.//from www. j a v a2s. c om * * @param dbConnection the db connection */ private static void closeConnection(Connection dbConnection) { if (dbConnection != null) { try { dbConnection.close(); } catch (SQLException e) { log.warn("Database error. Could not close database connection. Continuing with " + "others. - " + e.getMessage(), e); } } }
From source file:io.cloudslang.content.database.utils.SQLUtils.java
/** * Some databases (Sybase) throw exceptions during a database dump. This function processes that exception, and if it is that type, builds up the output of the command * * @param sqlException The exception to analyze * @return The output of the dump command * @throws java.sql.SQLException If it was not a successful dump command's exception. *//*from w ww . j a v a 2 s .c o m*/ public static String processDumpException(SQLException sqlException) throws SQLException { final String sqlState = sqlException.getSQLState(); if (sqlState != null && StringUtils.equalsIgnoreCase(sqlState, "s1000")) { SQLException f = sqlException; StringBuilder s = new StringBuilder(); s.append(f.getMessage()); while ((f = f.getNextException()) != null) { s.append("\n").append(f.getMessage()); } String str = s.toString(); if (StringUtils.containsIgnoreCase(str, "dump is complete")) return str; } throw sqlException; }
From source file:au.com.ish.derbydump.derbydump.metadata.Column.java
/** * @param data Clob to process and encode * @return String representation of Clob. *//* w w w .ja va 2 s. c om*/ static String processClobData(Clob data) { if (data == null) return "NULL"; Reader reader = null; BufferedReader br = null; try { reader = data.getCharacterStream(); br = new BufferedReader(reader); return processStringData(IOUtils.toString(br)); } catch (SQLException e) { LOGGER.error("Could not read data from stream :" + e.getErrorCode() + " - " + e.getMessage(), e); } catch (IOException e) { LOGGER.error("Could not read data from stream :" + e.getMessage(), e); } finally { IOUtils.closeQuietly(reader); IOUtils.closeQuietly(br); } return "NULL"; }