Example usage for java.sql SQLException toString

List of usage examples for java.sql SQLException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.apache.hive.jdbc.HiveStatement.java

/**
 * Closes the statement if there is one running. Do not change the the flags.
 * @throws SQLException If there is an error closing the statement
 */// w  w  w. j a v a2 s  .  c o  m
private void closeStatementIfNeeded() throws SQLException {
    try {
        if (stmtHandle != null) {
            TCloseOperationReq closeReq = new TCloseOperationReq(stmtHandle);
            TCloseOperationResp closeResp = client.CloseOperation(closeReq);
            Utils.verifySuccessWithInfo(closeResp.getStatus());
            stmtHandle = null;
        }
    } catch (SQLException e) {
        throw e;
    } catch (Exception e) {
        throw new SQLException(e.toString(), "08S01", e);
    }
}

From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java

@Override
public Answer delete(TestCaseCountryProperties object) {
    MessageEvent msg = null;/* w w w.  ja v  a 2 s.com*/
    final String query = "DELETE FROM `testcasecountryproperties` WHERE `Test`=? and `TestCase`=? and `Country`=? and `Property`=?";

    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, object.getTest());
            preStat.setString(2, object.getTestCase());
            preStat.setString(3, object.getCountry());
            preStat.setString(4, object.getProperty());

            preStat.executeUpdate();
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
            msg.setDescription(
                    msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to close connection : " + exception.toString());
        }
    }
    return new Answer(msg);
}

From source file:org.apache.hive.jdbc.HiveStatement.java

@Override
public void cancel() throws SQLException {
    checkConnection("cancel");
    if (isCancelled) {
        return;//from w w  w  . j a va 2 s.co  m
    }

    try {
        if (stmtHandle != null) {
            TCancelOperationReq cancelReq = new TCancelOperationReq(stmtHandle);
            TCancelOperationResp cancelResp = client.CancelOperation(cancelReq);
            Utils.verifySuccessWithInfo(cancelResp.getStatus());
        }
    } catch (SQLException e) {
        throw e;
    } catch (Exception e) {
        throw new SQLException(e.toString(), "08S01", e);
    }
    isCancelled = true;
}

From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java

@Override
public void insertTestCaseCountryProperties(TestCaseCountryProperties testCaseCountryProperties)
        throws CerberusException {
    boolean throwExcep = false;
    StringBuilder query = new StringBuilder();
    query.append(//from w ww .  j  a  v  a 2s.c om
            "INSERT INTO testcasecountryproperties (`Test`,`TestCase`,`Country`,`Property` ,`Description`,`Type`");
    query.append(",`Database`,`Value1`,`Value2`,`Length`,`RowLimit`,`Nature`,`RetryNb`,`RetryPeriod`) ");
    query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, testCaseCountryProperties.getTest());
            preStat.setString(2, testCaseCountryProperties.getTestCase());
            preStat.setString(3, testCaseCountryProperties.getCountry());
            preStat.setBytes(4, testCaseCountryProperties.getProperty().getBytes("UTF-8"));
            preStat.setBytes(5, testCaseCountryProperties.getDescription().getBytes("UTF-8"));
            preStat.setString(6, testCaseCountryProperties.getType());
            preStat.setString(7, testCaseCountryProperties.getDatabase());
            preStat.setBytes(8, testCaseCountryProperties.getValue1().getBytes("UTF-8"));
            preStat.setBytes(9, testCaseCountryProperties.getValue2().getBytes("UTF-8"));
            preStat.setInt(10, testCaseCountryProperties.getLength());
            preStat.setInt(11, testCaseCountryProperties.getRowLimit());
            preStat.setString(12, testCaseCountryProperties.getNature());
            preStat.setInt(13, testCaseCountryProperties.getRetryNb());
            preStat.setInt(14, testCaseCountryProperties.getRetryPeriod());

            preStat.executeUpdate();
            throwExcep = false;

        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } catch (UnsupportedEncodingException ex) {
            LOG.error(ex.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwExcep) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
    }
}

From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java

@Override
public void updateTestCaseCountryProperties(TestCaseCountryProperties testCaseCountryProperties)
        throws CerberusException {
    boolean throwExcep = false;
    StringBuilder query = new StringBuilder();
    query.append("UPDATE testcasecountryproperties SET ");
    query.append(//from  www.  j a  v a  2 s .  c o  m
            " `Description` = ?, `Type` = ? ,`Database` = ? ,Value1 = ?,Value2 = ?,`Length` = ?,  RowLimit = ?,  `Nature` = ? ,  `RetryNb` = ? ,  `RetryPeriod` = ? ");
    query.append(" WHERE Test = ? AND TestCase = ? AND Country = ? AND hex(`Property`) like hex(?)");

    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setBytes(1, testCaseCountryProperties.getDescription().getBytes("UTF-8"));
            preStat.setString(2, testCaseCountryProperties.getType());
            preStat.setString(3, testCaseCountryProperties.getDatabase());
            preStat.setBytes(4, testCaseCountryProperties.getValue1().getBytes("UTF-8"));
            preStat.setBytes(5, testCaseCountryProperties.getValue2().getBytes("UTF-8"));
            preStat.setInt(6, testCaseCountryProperties.getLength());
            preStat.setInt(7, testCaseCountryProperties.getRowLimit());
            preStat.setString(8, testCaseCountryProperties.getNature());
            preStat.setInt(9, testCaseCountryProperties.getRetryNb());
            preStat.setInt(10, testCaseCountryProperties.getRetryPeriod());
            preStat.setString(11, testCaseCountryProperties.getTest());
            preStat.setString(12, testCaseCountryProperties.getTestCase());
            preStat.setString(13, testCaseCountryProperties.getCountry());
            preStat.setBytes(14, testCaseCountryProperties.getProperty().getBytes("UTF-8"));

            preStat.executeUpdate();
            throwExcep = false;

        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } catch (UnsupportedEncodingException ex) {
            LOG.error(ex.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwExcep) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
    }
}

From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java

@Override
public Answer update(TestCaseCountryProperties object) {
    MessageEvent msg = null;//from w w w.j  a  v  a  2 s  . co  m
    final String query = "UPDATE testcasecountryproperties SET `Description` = ?, `Type` = ? ,`Database` = ? ,Value1 = ?,Value2 = ?,`Length` = ?,  RowLimit = ?,  `Nature` = ?,  `RetryNb` = ?,  `RetryPeriod` = ? WHERE Test = ? AND TestCase = ? AND Country = ? AND hex(`Property`) like hex(?)";

    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, object.getDescription());
            preStat.setString(2, object.getType());
            preStat.setString(3, object.getDatabase());
            preStat.setString(4, object.getValue1());
            preStat.setString(5, object.getValue2());
            preStat.setInt(6, object.getLength());
            preStat.setInt(7, object.getRowLimit());
            preStat.setString(8, object.getNature());
            preStat.setInt(9, object.getRetryNb());
            preStat.setInt(10, object.getRetryPeriod());
            preStat.setString(11, object.getTest());
            preStat.setString(12, object.getTestCase());
            preStat.setString(13, object.getCountry());
            preStat.setString(14, object.getProperty());

            preStat.executeUpdate();
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
            msg.setDescription(
                    msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to close connection : " + exception.toString());
        }
    }
    return new Answer(msg);
}

From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java

@Override
public List<String> findCountryByPropertyNameAndTestCase(String test, String testcase, String property) {
    List<String> result = new ArrayList<String>();

    final String query = "SELECT country FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND hex(`property`) like hex(?)";

    Connection connection = this.databaseSpring.connect();
    try {/*from   ww w.  j  a va 2 s  . c  om*/
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, test);
            preStat.setString(2, testcase);
            preStat.setBytes(3, property.getBytes("UTF-8"));

            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    String country = resultSet.getString("country");
                    if (country != null && !"".equals(country)) {
                        result.add(country);
                    }
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } catch (UnsupportedEncodingException ex) {
            LOG.error(ex.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }

    if (result.size() == 0) {
        return null;
    }

    return result;
}

From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java

@Override
public List<TestCaseCountryProperties> findListOfPropertyPerTestTestCase(String test, String testcase) {
    List<TestCaseCountryProperties> list = null;
    final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ?";

    Connection connection = this.databaseSpring.connect();
    try {//from  w w  w. ja v a2 s  .c o  m
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, test);
            preStat.setString(2, testcase);

            ResultSet resultSet = preStat.executeQuery();
            try {
                list = new ArrayList<TestCaseCountryProperties>();

                while (resultSet.next()) {
                    String country = resultSet.getString("country");
                    String property = resultSet.getString("property");
                    String description = resultSet.getString("description");
                    String type = resultSet.getString("type");
                    String database = resultSet.getString("database");
                    String value1 = resultSet.getString("value1");
                    String value2 = resultSet.getString("value2");
                    int length = resultSet.getInt("length");
                    int rowLimit = resultSet.getInt("rowLimit");
                    String nature = resultSet.getString("nature");
                    int retryNb = resultSet.getInt("RetryNb");
                    int retryPeriod = resultSet.getInt("RetryPeriod");
                    list.add(factoryTestCaseCountryProperties.create(test, testcase, country, property,
                            description, type, database, value1, value2, length, rowLimit, nature, retryNb,
                            retryPeriod));

                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException exception) {
            LOG.warn(exception.toString());
        }
    }
    return list;
}

From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java

@Override
public List<TestCaseCountryProperties> findDistinctPropertiesOfTestCase(String test, String testcase) {
    List<TestCaseCountryProperties> listProperties = null;
    final StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ?");
    query.append(/*from  w  w w.ja  v a 2s. c  o m*/
            " group by HEX(`property`), `type`, `database`, HEX(`value1`) ,  HEX(`value2`) , `length`, `rowlimit`, `nature`");

    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, test);
            preStat.setString(2, testcase);

            ResultSet resultSet = preStat.executeQuery();
            try {
                listProperties = new ArrayList<TestCaseCountryProperties>();

                while (resultSet.next()) {
                    String country = resultSet.getString("country");
                    String property = resultSet.getString("property");
                    String description = resultSet.getString("description");
                    String type = resultSet.getString("type");
                    String database = resultSet.getString("database");
                    String value1 = resultSet.getString("value1");
                    String value2 = resultSet.getString("value2");
                    int length = resultSet.getInt("length");
                    int rowLimit = resultSet.getInt("rowLimit");
                    String nature = resultSet.getString("nature");
                    int retryNb = resultSet.getInt("RetryNb");
                    int retryPeriod = resultSet.getInt("RetryPeriod");
                    listProperties.add(factoryTestCaseCountryProperties.create(test, testcase, country,
                            property, description, type, database, value1, value2, length, rowLimit, nature,
                            retryNb, retryPeriod));

                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return listProperties;
}

From source file:net.bull.javamelody.TestMonitoringFilter.java

private void monitorJdbcParts(Map<HttpParameter, String> parameters) throws IOException, ServletException {
    final Connection connection = TestDatabaseInformations.initH2();
    try {/* w w  w  .  jav  a2 s  .c  om*/
        parameters.put(HttpParameter.PART, HttpPart.DATABASE.getName());
        monitoring(parameters);
        parameters.put(HttpParameter.PART, HttpPart.DATABASE.getName());
        parameters.put(HttpParameter.REQUEST, "0");
        monitoring(parameters);
        parameters.put(HttpParameter.PART, HttpPart.CONNECTIONS.getName());
        monitoring(parameters);
        parameters.put(HttpParameter.PART, HttpPart.CONNECTIONS.getName());
        parameters.put(HttpParameter.FORMAT, "htmlbody");
        monitoring(parameters);
        parameters.remove(HttpParameter.FORMAT);
        parameters.put(HttpParameter.REQUEST, "0");
        monitoring(parameters);
        parameters.remove(HttpParameter.REQUEST);
    } finally {
        try {
            connection.close();
        } catch (final SQLException e) {
            LOG.warn(e.toString(), e);
        }
    }
}