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.cerberus.crud.dao.impl.TestCaseExecutionDAO.java

@Override
public List<String> getIDListOfLastExecutions(String test, String testcase, String country) {
    List<String> list = null;
    final String query = "SELECT ID FROM testcaseexecution WHERE test = ? AND testcase = ? AND country = ? AND controlStatus='OK' ORDER BY id DESC LIMIT 200";

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

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

                while (resultSet.next()) {
                    list.add(resultSet.getString("ID"));
                }
            } 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 list;
}

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

@Override
public TestCaseExecution findTCExecutionByKey(long id) throws CerberusException {
    TestCaseExecution result = null;/*from w  ww  .  j av a  2  s . c o  m*/
    final String query = "SELECT * FROM testcaseexecution exe, application app WHERE exe.application = app.application AND ID = ?";

    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }

    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        preStat.setLong(1, id);

        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.first()) {
                    result = this.loadTestCaseExecutionAndApplicationFromResultSet(resultSet);
                }
            } 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 result;
}

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

@Override
public List<String> findDistinctTag(boolean withUUIDTag) throws CerberusException {
    List<String> list = null;
    StringBuilder query = new StringBuilder();
    query.append("select distinct tag from testcaseexecution exe ").append("where tag != '' ");
    if (!withUUIDTag) {
        query.append(" and length(tag) != length('c3888898-c65a-11e3-9b3e-0000004047e0')");
    }//from  w  ww  .  j  a  v a 2  s. com
    query.append(" UNION select distinct tag from testcaseexecutionqueue where tag !='' ");

    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                list = new ArrayList<String>();

                while (resultSet.next()) {
                    list.add(resultSet.getString("tag"));
                }
            } 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 list;
}

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

@Override
public TestCaseExecution findLastTestCaseExecutionNotPE(String test, String testCase) throws CerberusException {
    TestCaseExecution result = null;/*from w ww  .j  a v  a2  s .com*/
    StringBuilder query = new StringBuilder();
    query.append("SELECT exe.*  FROM `testcaseexecution` exe ");
    query.append(" WHERE Test = ? and TestCase= ? and ID = ");
    query.append(" (SELECT MAX(ID) from `testcaseexecution` ");
    query.append("WHERE Test= ? and TestCase= ? and ControlStatus!='PE')");

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

        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.first()) {
                    result = loadFromResultSet(resultSet);
                }
            } 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 result;
}

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

@Override
public TestCaseExecution findLastTCExecutionByCriteria(String test, String testcase, String environment,
        String country, String build, String revision) throws CerberusException {
    TestCaseExecution result = null;/* w  w w. ja  v a2 s  .  c  o m*/
    final String query = new StringBuffer("SELECT exe.* FROM testcaseexecution exe ")
            .append("WHERE exe.test = ? AND exe.testcase = ? AND exe.environment = ? ")
            .append("AND exe.country = ? AND exe.build = ? AND exe.revision = ? ")
            .append("ORDER BY exe.id DESC").toString();

    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        preStat.setString(1, test);
        preStat.setString(2, testcase);
        preStat.setString(3, environment);
        preStat.setString(4, country);
        preStat.setString(5, build);
        preStat.setString(6, revision);

        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.first()) {
                    result = this.loadFromResultSet(resultSet);
                } else {
                    throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
                }
            } 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 result;
}

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

@Override
public TestCaseExecution findLastTCExecutionByCriteria(String test, String testCase, String environment,
        String country, String build, String revision, String browser, String browserVersion, String ip,
        String port, String tag) {
    TestCaseExecution result = null;//w ww.  j a  va 2  s .c o m
    final String query = new StringBuffer("SELECT exe.* FROM testcaseexecution exe ")
            .append("WHERE exe.test = ? AND exe.testcase = ? ")
            .append("AND exe.environment LIKE ? AND exe.country = ? AND exe.build LIKE ? ")
            .append("AND exe.revision LIKE ? AND exe.browser = ? AND exe.browserfullversion LIKE ? ")
            .append("AND exe.ip LIKE ? AND exe.port LIKE ? AND exe.tag LIKE ? ").append("ORDER BY exe.id DESC")
            .toString();

    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        preStat.setString(1, test);
        preStat.setString(2, testCase);
        preStat.setString(3, ParameterParserUtil.wildcardIfEmpty(environment));
        preStat.setString(4, country);
        preStat.setString(5, ParameterParserUtil.wildcardIfEmpty(build));
        preStat.setString(6, ParameterParserUtil.wildcardIfEmpty(revision));
        preStat.setString(7, browser);
        preStat.setString(8, ParameterParserUtil.wildcardIfEmpty(browserVersion));
        preStat.setString(9, ParameterParserUtil.wildcardIfEmpty(ip));
        preStat.setString(10, ParameterParserUtil.wildcardIfEmpty(port));
        preStat.setString(11, ParameterParserUtil.wildcardIfEmpty(tag));

        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.first()) {
                    result = this.loadFromResultSet(resultSet);
                }
            } 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 result;
}

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

@Override
public AnswerItem readByKey(long executionId) {
    AnswerItem ans = new AnswerItem();
    TestCaseExecution result = null;/* w w  w  . ja v a  2s  .  c  om*/
    final String query = "SELECT * FROM `testcaseexecution` exe WHERE exe.`id` = ?";
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));

    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setLong(1, executionId);
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.first()) {
                    result = loadFromResultSet(resultSet);
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                    msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)
                            .replace("%OPERATION%", "SELECT"));
                    ans.setItem(result);
                } else {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                }
            } 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 {
                resultSet.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 {
            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());
        }
    }

    //sets the message
    ans.setResultMessage(msg);
    return ans;
}

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

@Override
public List<TestCaseExecution> findExecutionsByCampaignNameAndTag(String campaign, String tag)
        throws CerberusException {
    List<TestCaseExecution> campaignTestCaseExecutions = null;
    boolean throwException = false;

    final String query = new StringBuffer("select exe.*, app.* from ( ").append("select exe.* ")
            .append("from testcaseexecution exe ").append("inner join testbatterycontent tbc ")
            .append("on tbc.Test = exe.Test ").append("and tbc.TestCase = exe.TestCase ")
            .append("inner join campaigncontent cc ").append("on cc.testbattery = tbc.testbattery ")
            .append("where tag is not null ").append("and cc.campaign = ? ").append("and tag = ? ")
            .append("order by test, testcase, ID desc) as exe, application app ")
            .append("where exe.application = app.application ")
            .append("group by exe.test, exe.testcase, exe.Environment, exe.Browser, exe.Country ").toString();

    Connection connection = this.databaseSpring.connect();
    try {// ww w.j ava 2s.c o m
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, campaign);
            preStat.setString(2, tag);

            ResultSet resultSet = preStat.executeQuery();
            try {
                if (!(resultSet.first())) {
                    throwException = true;
                } else {
                    campaignTestCaseExecutions = new ArrayList<TestCaseExecution>();
                    do {
                        campaignTestCaseExecutions.add(this.loadFromResultSet(resultSet));
                    } while (resultSet.next());
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                if (!(resultSet == null)) {
                    resultSet.close();
                }
            }
        } catch (Exception exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (Exception exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwException) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));
    }

    return campaignTestCaseExecutions;
}

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

@Override
public AnswerList findTagList(int tagnumber) {
    AnswerList response = new AnswerList();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    List<String> list = null;
    StringBuilder query = new StringBuilder();

    query.append("SELECT DISTINCT exe.tag FROM testcaseexecution exe WHERE tag != ''");

    if (tagnumber != 0) {
        query.append("ORDER BY id desc LIMIT ");
        query.append(tagnumber);//from  ww w  . j  a  va2 s  .c o  m
    }

    query.append(";");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                list = new ArrayList<String>();

                while (resultSet.next()) {
                    list.add(resultSet.getString("exe.tag"));
                }
                msg.setDescription(
                        msg.getDescription().replace("%ITEM%", "TagList").replace("%OPERATION%", "SELECT"));
            } 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%",
                        "Unable to retrieve the list of entries!"));
            } finally {
                resultSet.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%", "Unable to retrieve the list of entries!"));
        } 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%", "Unable to retrieve the list of entries!"));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }

    response.setResultMessage(msg);
    response.setDataList(list);
    return response;
}

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

@Override
public List<TestCaseExecution> findExecutionbyCriteria1(String dateLimit, String test, String testCase,
        String application, String country, String environment, String controlStatus, String status)
        throws CerberusException {
    List<TestCaseExecution> myTestCaseExecutions = null;
    TestCaseExecution Execution;//from w ww  .j  a v a2 s .  com
    boolean throwException = false;
    final String query = new StringBuffer("SELECT exe.*, tec.*, app.* FROM testcaseexecution exe ")
            .append("LEFT JOIN testcase tec ON exe.test = tec.test AND exe.testcase = tec.testcase ")
            .append("LEFT JOIN application app ON exe.application = app.application ")
            .append("WHERE exe.start > ? AND exe.test LIKE ? AND exe.testcase LIKE ? AND exe.environment LIKE ? ")
            .append("AND exe.country LIKE ? AND exe.application LIKE ? AND exe.controlstatus LIKE ? ")
            .append("AND exe.status LIKE ?").toString();

    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, dateLimit);
            preStat.setString(2, test);
            preStat.setString(3, testCase);
            preStat.setString(4, environment);
            preStat.setString(5, country);
            preStat.setString(6, application);
            preStat.setString(7, controlStatus);
            preStat.setString(8, status);

            ResultSet resultSet = preStat.executeQuery();
            try {
                if (!(resultSet.first())) {
                    throwException = true;
                } else {
                    myTestCaseExecutions = new ArrayList<TestCaseExecution>();
                    do {
                        Execution = this.loadWithDependenciesFromResultSet(resultSet);

                        myTestCaseExecutions.add(Execution);
                    } while (resultSet.next());
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                if (!(resultSet == null)) {
                    resultSet.close();
                }
            }
        } catch (Exception exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (Exception exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwException) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));
    }

    return myTestCaseExecutions;
}