Example usage for java.sql SQLException getMessage

List of usage examples for java.sql SQLException getMessage

Introduction

In this page you can find the example usage for java.sql SQLException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:Main.java

public static void createBlobClobTables(Statement stmt) throws Exception {
    String Sql = "CREATE TABLE BlobClob(Id NUMBER(3), b BLOB, c CLOB)";

    try {//from   ww  w  . jav a  2 s. c  om
        stmt.executeUpdate("DROP TABLE BlobClob");
    } catch (SQLException se) {
        if (se.getErrorCode() == 942)
            System.out.println("Error dropping BlobClob table:" + se.getMessage());
    }
    if (stmt.executeUpdate(Sql) == 0)
        System.out.println("BlobClob table created...");

}

From source file:com.test.db.MySqlConnection.java

/**
 * Closes connection pool/*from  w w  w .j a  v a  2 s.  co m*/
 */
public static void close() {
    if (ds.isClosed())
        return;

    try {
        ds.close();
    } catch (SQLException e) {
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:br.ufmt.ic.pawii.util.Estados.java

public static String getEstados(String estado, String nome, String email) {
    try {//from   ww  w .j a va  2s.c om

        String strCidades;

        Statement stm;

        Connection con = ConnBD.getConnection();

        if (con == null) {
            throw new SQLException("Erro conectando");
        }

        stm = con.createStatement();

        String sql = "SELECT codigo,municipio FROM municipios" + " WHERE uf='" + estado
                + "' ORDER BY municipio ASC";

        ResultSet rs = stm.executeQuery(sql);

        JSONArray cidades = new JSONArray();

        while (rs.next()) {

            String codigo = rs.getString(1);
            String cidade = rs.getString(2);

            JSONObject jsonCidade = new JSONObject();
            jsonCidade.put("codigo", codigo);
            jsonCidade.put("nome", cidade);
            cidades.put(jsonCidade);
        }

        JSONObject jsonRetorno = new JSONObject();
        jsonRetorno.put("cidades", cidades);
        jsonRetorno.put("seuNome", nome);
        jsonRetorno.put("seuEmail", email);

        strCidades = jsonRetorno.toString();

        return strCidades;

    } catch (SQLException ex) {
        System.out.println("Error: " + ex.getMessage());
    } catch (Exception e) {
        System.out.println("Error: " + e.getMessage());
    }

    return null;
}

From source file:com.test.db.MySqlConnection.java

/**
 * Closes active MySQL connection//  w  w w. j  a v a 2s  .co  m
 *
 * @param connection the active connection
 */
public static void close(Connection connection) {
    if (connection == null)
        return;

    try {
        if (connection.isClosed())
            return;

        connection.close();
    } catch (SQLException e) {
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:com.test.db.MySqlConnection.java

/**
 * Closes active MySQL connection/* w w  w . j ava2 s  .  co m*/
 *
 * @param resultSet the active connection
 */
public static void close(ResultSet resultSet) {
    if (resultSet == null)
        return;

    try {
        if (resultSet.isClosed())
            return;

        resultSet.close();
    } catch (SQLException e) {
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:com.test.db.MySqlConnection.java

/**
 * Closes active MySQL connection//ww w  .j  av a 2  s. co m
 *
 * @param statement the active connection
 */
public static void close(Statement statement) {
    if (statement == null)
        return;

    try {
        if (statement.isClosed())
            return;

        statement.close();
    } catch (SQLException e) {
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:com.qualogy.qafe.business.resource.rdb.query.enhancer.EnhancementManager.java

public static QueryContainer enhance(QueryContainer container, RDBDatasource dsResource) {
    if ((dsResource == null) || (dsResource.getDataSource() == null)) {
        throw new IllegalArgumentException(
                "Properties not read correctly or properties are incorrect, loading datasource failed");
    }/*from  w  w  w .  j  av  a 2s  .c om*/

    DataSource dataSource = dsResource.getDataSource();

    Connection con = null;

    try {
        con = dataSource.getConnection();

        DatabaseMetaData md = con.getMetaData();

        for (Iterator<Query> iter = container.values().iterator(); iter.hasNext();) {
            Query query = (Query) iter.next();

            if (query instanceof Batch) {
                for (Iterator<Query> iterator = ((Batch) query).getQueries().iterator(); iterator.hasNext();) {
                    Query batchQuery = (Query) iterator.next();
                    batchQuery = enhance(batchQuery, container, md);
                }
            } else {
                query = enhance(query, container, md);
            }

            container.update(query);
        }
    } catch (SQLException e) {
        String error = e.getMessage() + "[ on source ]" + dsResource.toString();
        throw new EnhancementFailedException(error);
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
                String error = e.getMessage() + "[ on source ]" + dsResource.toString();
                throw new EnhancementFailedException(error);
            }
        }
    }

    return container;
}

From source file:com.espertech.esper.epl.db.ConnectionCache.java

/**
 * Close resources./*from   w  ww  .j av  a 2  s .co m*/
 * @param pair is the resources to close.
 */
protected static void close(Pair<Connection, PreparedStatement> pair) {
    log.info(".close Closing statement and connection");
    try {
        pair.getSecond().close();
    } catch (SQLException ex) {
        try {
            pair.getFirst().close();
        } catch (SQLException e) {
            log.error("Error closing JDBC connection:" + e.getMessage(), e);
        }
        throw new EPException("Error closing statement", ex);
    }

    try {
        pair.getFirst().close();
    } catch (SQLException ex) {
        throw new EPException("Error closing statement", ex);
    }
}

From source file:br.gov.jfrj.siga.persistencia.oracle.JDBCUtilOracle.java

public static Connection getConnectionPool(final String dataSource) {

    Context initContext = null;//from   w w  w.ja  v  a 2  s  .  co m
    Context envContext = null;
    Connection conn = null;

    try {
        JDBCUtilOracle.log.debug("Criando variavel de contexto");
        initContext = new InitialContext();

        envContext = (Context) initContext.lookup("java:/comp/env");
        JDBCUtilOracle.log.debug("Criando datasource ");
        final DataSource ds = (DataSource) envContext.lookup(dataSource);
        conn = ds.getConnection();

    } catch (final NamingException e) {
        JDBCUtilOracle.log.error(Messages.getString("Oracle.LookUpErro"));
        System.err.print(Messages.getString("Oracle.LookUpErro") + e.getMessage());

    } catch (final SQLException ex) {
        System.err.print(Messages.getString("Oracle.SQLErro") + ex.getMessage());
    }
    return conn;
}

From source file:com.wso2telco.dao.TransactionDAO.java

/**
 * Insert sub value.// ww w  .j a  v a2s.  c  om
 *
 * @param token the context id
 * @param sub   the status code
 * @throws Exception the exception
 */
public static void insertTokenScopeLog(String token, String sub) throws Exception {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DbUtil.getConnectDBConnection();
        String query = "INSERT INTO scope_log ( access_token,sub) VALUES " + "(? ,?);";
        ps = conn.prepareStatement(query);
        ps.setString(1, token);
        ps.setString(2, sub);
        ps.execute();
        log.debug("Sub value inserted successfully");
    } catch (SQLException e) {
        handleException("Error in inserting transaction log record : " + e.getMessage(), e);
    } finally {
        DbUtil.closeAllConnections(ps, conn, null);
    }
}