List of usage examples for java.sql SQLException toString
public String toString()
From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java
@Override public List<String> findCountryByProperty(TestCaseCountryProperties testCaseCountryProperties) { List<String> list = null; final StringBuilder query = new StringBuilder(); query.append("SELECT country FROM testcasecountryproperties WHERE test = ? AND testcase = ?"); query.append(/*w ww. j a v a 2 s. c o m*/ " AND HEX(`property`) = hex(?) AND `type` =? AND `database` =? AND hex(`value1`) like hex( ? ) AND hex(`value2`) like hex( ? ) AND `length` = ? "); query.append(" AND `rowlimit` = ? AND `nature` = ?"); // Debug message on SQL. if (LOG.isDebugEnabled()) { LOG.debug("SQL : " + query.toString()); } Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { preStat.setString(1, testCaseCountryProperties.getTest()); preStat.setString(2, testCaseCountryProperties.getTestCase()); preStat.setBytes(3, testCaseCountryProperties.getProperty().getBytes("UTF-8")); preStat.setString(4, testCaseCountryProperties.getType()); preStat.setString(5, testCaseCountryProperties.getDatabase()); preStat.setBytes(6, testCaseCountryProperties.getValue1().getBytes("UTF-8")); preStat.setBytes(7, testCaseCountryProperties.getValue2().getBytes("UTF-8")); preStat.setString(8, String.valueOf(testCaseCountryProperties.getLength())); preStat.setString(9, String.valueOf(testCaseCountryProperties.getRowLimit())); preStat.setString(10, testCaseCountryProperties.getNature()); ResultSet resultSet = preStat.executeQuery(); try { list = new ArrayList<String>(); String valueToAdd; while (resultSet.next()) { valueToAdd = resultSet.getString("Country") == null ? "" : resultSet.getString("Country"); list.add(valueToAdd); } } 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()); } } return list; }
From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java
@Override public TestCaseCountryProperties findTestCaseCountryPropertiesByKey(String test, String testcase, String country, String property) throws CerberusException { TestCaseCountryProperties result = null; boolean throwException = false; final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND country = ? AND hex(`property`) = hex(?)"; Connection connection = this.databaseSpring.connect(); try {// ww w . ja v a 2 s .c o m PreparedStatement preStat = connection.prepareStatement(query); try { preStat.setString(1, test); preStat.setString(2, testcase); preStat.setString(3, country); preStat.setBytes(4, property.getBytes("UTF-8")); ResultSet resultSet = preStat.executeQuery(); try { if (resultSet.first()) { 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"); result = factoryTestCaseCountryProperties.create(test, testcase, country, property, description, type, database, value1, value2, length, rowLimit, nature, retryNb, retryPeriod); } else { throwException = true; } } 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 (throwException) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND)); } return result; }
From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java
@Override public Answer create(TestCaseCountryProperties object) { MessageEvent msg = null;/*from w w w . j a va 2 s . c o m*/ StringBuilder query = new StringBuilder(); query.append( "INSERT INTO testcasecountryproperties (`Test`,`TestCase`,`Country`,`Property`,`Description`,`Type`"); query.append(",`Database`,`Value1`,`Value2`,`Length`,`RowLimit`,`Nature`,`RetryNb`,`RetryPeriod`) "); query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); // Debug message on SQL. if (LOG.isDebugEnabled()) { LOG.debug("SQL : " + query.toString()); } Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { preStat.setString(1, object.getTest()); preStat.setString(2, object.getTestCase()); preStat.setString(3, object.getCountry()); preStat.setString(4, object.getProperty()); preStat.setString(5, object.getDescription()); preStat.setString(6, object.getType()); preStat.setString(7, object.getDatabase()); preStat.setString(8, object.getValue1()); preStat.setString(9, object.getValue2()); preStat.setInt(10, object.getLength()); preStat.setInt(11, object.getRowLimit()); preStat.setString(12, object.getNature()); preStat.setInt(13, object.getRetryNb()); preStat.setInt(14, object.getRetryPeriod()); preStat.executeUpdate(); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK); msg.setDescription( msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT")); } catch (SQLException exception) { LOG.error("Unable to execute query : " + exception.toString()); if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE); msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME) .replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString())); } else { 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.error("Unable to close connection : " + exception.toString()); } } return new Answer(msg); }
From source file:org.cerberus.crud.dao.impl.TestCaseCountryPropertiesDAO.java
@Override public List<TestCaseCountryProperties> findListOfPropertyPerTestTestCaseCountry(String test, String testcase, String country) {//w w w.j a v a 2 s .c o m List<TestCaseCountryProperties> list = null; final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND country = ?"; // Debug message on SQL. if (LOG.isDebugEnabled()) { LOG.debug("SQL : " + query); LOG.debug("SQL.param.test : " + test); LOG.debug("SQL.param.testcase : " + testcase); LOG.debug("SQL.param.country : " + country); } Connection connection = this.databaseSpring.connect(); try { 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<TestCaseCountryProperties>(); while (resultSet.next()) { 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 e) { LOG.warn(e.toString()); } } return list; }
From source file:org.cerberus.crud.dao.impl.ApplicationObjectDAO.java
@Override public AnswerList readByCriteria(int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) { AnswerList response = new AnswerList(); MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "")); List<ApplicationObject> objectList = new ArrayList<ApplicationObject>(); StringBuilder searchSQL = new StringBuilder(); List<String> individalColumnSearchValues = new ArrayList<String>(); StringBuilder query = new StringBuilder(); //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that //were applied -- used for pagination p query.append("SELECT SQL_CALC_FOUND_ROWS * FROM applicationobject "); searchSQL.append(" where 1=1 "); if (!StringUtil.isNullOrEmpty(searchTerm)) { searchSQL.append(" and (`Application` like ?"); searchSQL.append(" or `Object` like ?"); searchSQL.append(" or `Value` like ?"); searchSQL.append(" or `ScreenshotFileName` like ?"); searchSQL.append(" or `UsrCreated` like ?"); searchSQL.append(" or `DateCreated` like ?"); searchSQL.append(" or `UsrModif` like ?"); searchSQL.append(" or `DateModif` like ?)"); }/*from www .j a v a 2 s . c o m*/ if (individualSearch != null && !individualSearch.isEmpty()) { searchSQL.append(" and ( 1=1 "); for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) { searchSQL.append(" and "); searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue())); individalColumnSearchValues.addAll(entry.getValue()); } searchSQL.append(" )"); } query.append(searchSQL); if (!StringUtil.isNullOrEmpty(column)) { query.append(" order by `").append(column).append("` ").append(dir); } if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) { query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED); } else { query.append(" limit ").append(start).append(" , ").append(amount); } // Debug message on SQL. if (LOG.isDebugEnabled()) { LOG.debug("SQL : " + query.toString()); } Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { int i = 1; if (!StringUtil.isNullOrEmpty(searchTerm)) { preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); } for (String individualColumnSearchValue : individalColumnSearchValues) { preStat.setString(i++, individualColumnSearchValue); } ResultSet resultSet = preStat.executeQuery(); try { //gets the data while (resultSet.next()) { objectList.add(this.loadFromResultSet(resultSet)); } //get the total number of rows resultSet = preStat.executeQuery("SELECT FOUND_ROWS()"); int nrTotalRows = 0; if (resultSet != null && resultSet.next()) { nrTotalRows = resultSet.getInt(1); } if (objectList.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList. LOG.error("Partial Result in the query."); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED)); response = new AnswerList(objectList, nrTotalRows); } else if (objectList.size() <= 0) { msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND); response = new AnswerList(objectList, nrTotalRows); } else { msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK); msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME) .replace("%OPERATION%", "SELECT")); response = new AnswerList(objectList, nrTotalRows); } } 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 { if (resultSet != null) { 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 { if (preStat != null) { 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 (!this.databaseSpring.isOnTransaction()) { if (connection != null) { connection.close(); } } } catch (SQLException exception) { LOG.warn("Unable to close connection : " + exception.toString()); } } response.setResultMessage(msg); response.setDataList(objectList); return response; }
From source file:org.cerberus.crud.dao.impl.ApplicationObjectDAO.java
@Override public AnswerList readByApplicationByCriteria(String application, int start, int amount, String column, String dir, String searchTerm, Map<String, List<String>> individualSearch) { AnswerList response = new AnswerList(); MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "")); List<ApplicationObject> objectList = new ArrayList<ApplicationObject>(); StringBuilder searchSQL = new StringBuilder(); List<String> individalColumnSearchValues = new ArrayList<String>(); StringBuilder query = new StringBuilder(); //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that //were applied -- used for pagination p query.append("SELECT SQL_CALC_FOUND_ROWS * FROM applicationobject "); searchSQL.append(" where 1=1 "); if (!StringUtil.isNullOrEmpty(searchTerm)) { searchSQL.append(" and (`Application` like ?"); searchSQL.append(" or `Object` like ?"); searchSQL.append(" or `Value` like ?"); searchSQL.append(" or `ScreenshotFileName` like ?"); searchSQL.append(" or `UsrCreated` like ?"); searchSQL.append(" or `DateCreated` like ?"); searchSQL.append(" or `UsrModif` like ?"); searchSQL.append(" or `DateModif` like ?)"); }/*from w w w. j a v a 2 s . c o m*/ if (individualSearch != null && !individualSearch.isEmpty()) { searchSQL.append(" and ( 1=1 "); for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) { searchSQL.append(" and "); searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue())); individalColumnSearchValues.addAll(entry.getValue()); } searchSQL.append(" )"); } if (!StringUtil.isNullOrEmpty(application)) { searchSQL.append(" and (`Application` = ? )"); } query.append(searchSQL); if (!StringUtil.isNullOrEmpty(column)) { query.append(" order by `").append(column).append("` ").append(dir); } if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) { query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED); } else { query.append(" limit ").append(start).append(" , ").append(amount); } // Debug message on SQL. if (LOG.isDebugEnabled()) { LOG.debug("SQL : " + query.toString()); } Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { int i = 1; if (!StringUtil.isNullOrEmpty(searchTerm)) { preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); preStat.setString(i++, "%" + searchTerm + "%"); } for (String individualColumnSearchValue : individalColumnSearchValues) { preStat.setString(i++, individualColumnSearchValue); } if (!StringUtil.isNullOrEmpty(application)) { preStat.setString(i++, application); } ResultSet resultSet = preStat.executeQuery(); try { //gets the data while (resultSet.next()) { objectList.add(this.loadFromResultSet(resultSet)); } //get the total number of rows resultSet = preStat.executeQuery("SELECT FOUND_ROWS()"); int nrTotalRows = 0; if (resultSet != null && resultSet.next()) { nrTotalRows = resultSet.getInt(1); } if (objectList.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList. LOG.error("Partial Result in the query."); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT); msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED)); response = new AnswerList(objectList, nrTotalRows); } else if (objectList.size() <= 0) { msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND); response = new AnswerList(objectList, nrTotalRows); } else { msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK); msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME) .replace("%OPERATION%", "SELECT")); response = new AnswerList(objectList, nrTotalRows); } } 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 { if (resultSet != null) { 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 { if (preStat != null) { 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 (!this.databaseSpring.isOnTransaction()) { if (connection != null) { connection.close(); } } } catch (SQLException exception) { LOG.warn("Unable to close connection : " + exception.toString()); } } response.setResultMessage(msg); response.setDataList(objectList); return response; }
From source file:org.cerberus.crud.dao.impl.TestBatteryDAO.java
@Override public boolean deleteTestBattery(TestBattery testBattery) { final StringBuffer query = new StringBuffer("DELETE FROM `testbattery` WHERE testbatteryID=?"); Connection connection = this.databaseSpring.connect(); try {//from ww w. j a v a2 s. c o m PreparedStatement preStat = connection.prepareStatement(query.toString()); preStat.setInt(1, testBattery.getTestbatteryID()); try { return (preStat.executeUpdate() == 1); } catch (SQLException exception) { MyLogger.log(TestBatteryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { MyLogger.log(TestBatteryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(TestBatteryDAO.class.getName(), Level.WARN, e.toString()); } } return false; }
From source file:org.cerberus.crud.dao.impl.TestBatteryDAO.java
@Override public boolean createTestBattery(TestBattery testBattery) { final StringBuffer query = new StringBuffer( "INSERT INTO `testbattery` (`testbattery`, `Description`) VALUES (?, ?)"); Connection connection = this.databaseSpring.connect(); try {// w w w.j av a 2 s . c o m PreparedStatement preStat = connection.prepareStatement(query.toString()); preStat.setString(1, testBattery.getTestbattery()); preStat.setString(2, testBattery.getDescription()); try { return (preStat.executeUpdate() == 1); } catch (SQLException exception) { MyLogger.log(TestBatteryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { MyLogger.log(TestBatteryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(TestBatteryDAO.class.getName(), Level.WARN, e.toString()); } } return false; }
From source file:org.cerberus.crud.dao.impl.TestBatteryDAO.java
@Override public boolean updateTestBattery(TestBattery testBattery) { final StringBuffer query = new StringBuffer( "UPDATE `testbattery` set `testbattery` = ?, `Description` = ? WHERE `testbatteryID` = ?"); Connection connection = this.databaseSpring.connect(); try {/*from w w w . j a v a 2 s . c om*/ PreparedStatement preStat = connection.prepareStatement(query.toString()); preStat.setString(1, testBattery.getTestbattery()); preStat.setString(2, testBattery.getDescription()); preStat.setInt(3, testBattery.getTestbatteryID()); try { return (preStat.executeUpdate() == 1); } catch (SQLException exception) { MyLogger.log(TestBatteryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { MyLogger.log(TestBatteryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(TestBatteryDAO.class.getName(), Level.WARN, e.toString()); } } return false; }
From source file:org.cerberus.crud.dao.impl.TestBatteryDAO.java
@Override public TestBattery findTestBatteryByKey(Integer testBatteryID) throws CerberusException { boolean throwEx = false; final String query = "SELECT * FROM testbattery t WHERE t.testbatteryID = ?"; TestBattery testBattery = null;/*from w ww . j a v a 2 s . co m*/ Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query); preStat.setInt(1, testBatteryID); try { ResultSet resultSet = preStat.executeQuery(); try { if (resultSet.first()) { testBattery = this.loadFromResultSet(resultSet); } } catch (SQLException exception) { MyLogger.log(TestBatteryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { resultSet.close(); } } catch (SQLException exception) { MyLogger.log(TestBatteryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { MyLogger.log(TestBatteryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(TestBatteryDAO.class.getName(), Level.WARN, e.toString()); } } if (throwEx) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND)); } return testBattery; }