/** * Executes a select query. * * @param query The query to execute * @return The list of selected rows converted in dtos. */ protected List<o> executeSelectQuery(String query) { Connection dbConnection = H2DAOFactory.createConnection(); if (dbConnection != null) { try { Statement stmt = dbConnection.createStatement(); LOGGER.info("Execute query: " + query); return convertToDto(stmt.executeQuery(query)); } catch (SQLException e) { LOGGER.warning("SQLExeption (" + e.getErrorCode() + ") occured trying to execute query."); } finally { try { dbConnection.close(); } catch (SQLException e) { LOGGER.warning( "SQLExeption (" + e.getErrorCode() + ") occured while closing connection."); } } } return null; }
/** * Executes an update Query. * * @param query The query to execute. * @return Count of affected rows in the database or -1 on error. */ protected int executeSaveUpdateQuery(String query) { Connection dbConnection = H2DAOFactory.createConnection(); if (dbConnection != null) { try { Statement stmt = dbConnection.createStatement(); LOGGER.info("Execute query: " + query); return stmt.executeUpdate(query); } catch (SQLException e) { LOGGER.warning("SQLExeption (" + e.getErrorCode() + ") occured while executing query."); e.printStackTrace(); } finally { try { dbConnection.close(); } catch (SQLException e) { LOGGER.warning( "SQLExeption (" + e.getErrorCode() + ") occured while closing connection."); } } } return -1; }