List of usage examples for java.sql Statement getResultSet
ResultSet getResultSet() throws SQLException;
ResultSet
object. From source file:com.redhat.lightblue.rest.crud.ITCaseCrudResourceRDBMSTest.java
@Test public void testDelete() throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, URISyntaxException, JSONException { try {/*ww w . ja va 2s. c o m*/ Context initCtx = new InitialContext(); DataSource ds = (DataSource) initCtx.lookup("java:/mydatasource"); Connection conn = ds.getConnection(); Statement stmt = conn.createStatement(); stmt.execute( "CREATE TABLE Country ( name varchar(255), iso2code varchar(255), iso3code varchar(255) );"); stmt.execute("INSERT INTO Country (name,iso2code,iso3code) VALUES ('a','CA','c');"); stmt.close(); conn.close(); Assert.assertNotNull("CrudResource was not injected by the container", cutCrudResource); RestConfiguration.setDatasources(new DataSourcesConfiguration( JsonUtils.json(readConfigFile(RestConfiguration.DATASOURCE_FILENAME)))); RestConfiguration.setFactory(new LightblueFactory(RestConfiguration.getDatasources())); String expectedCreated = readFile("expectedCreated.json"); String metadata = readFile("metadata.json").replaceAll("YYZ", " DELETE FROM Country WHERE ISO2CODE=:ISO2CODE;"); EntityMetadata em = RestConfiguration.getFactory().getJSONParser() .parseEntityMetadata(JsonUtils.json(metadata)); RestConfiguration.getFactory().getMetadata().createNewMetadata(em); EntityMetadata em2 = RestConfiguration.getFactory().getMetadata().getEntityMetadata("country", "1.0.0"); String resultCreated = RestConfiguration.getFactory().getJSONParser().convert(em2).toString(); JSONAssert.assertEquals(expectedCreated, resultCreated, false); String expectedDeleted = readFile("expectedDeleted.json"); String resultDeleted = cutCrudResource.delete("country", "1.0.0", readFile("resultDeleted.json")) .getEntity().toString(); //System.err.println("!!!!!!!!!!!!!!!!!" + resultDeleted); ds = (DataSource) initCtx.lookup("java:/mydatasource"); conn = ds.getConnection(); stmt = conn.createStatement(); stmt.execute("SELECT * FROM Country;"); ResultSet resultSet = stmt.getResultSet(); Assert.assertEquals(false, resultSet.next()); JSONAssert.assertEquals(expectedDeleted, resultDeleted, false); } catch (NamingException | SQLException ex) { throw new IllegalStateException(ex); } mongo.dropDatabase(DB_NAME); }
From source file:com.redhat.lightblue.rest.crud.ITCaseCrudResourceRDBMSTest.java
@Test public void testUpdate() throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, URISyntaxException, JSONException { try {/*from w w w . j a v a2 s. c o m*/ Context initCtx = new InitialContext(); DataSource ds = (DataSource) initCtx.lookup("java:/mydatasource"); Connection conn = ds.getConnection(); Statement stmt = conn.createStatement(); stmt.execute( "CREATE TABLE Country ( name varchar(255), iso2code varchar(255), iso3code varchar(255) );"); stmt.execute("INSERT INTO Country (name,iso2code,iso3code) VALUES ('a','CA','c');"); stmt.close(); conn.close(); Assert.assertNotNull("CrudResource was not injected by the container", cutCrudResource); RestConfiguration.setDatasources(new DataSourcesConfiguration( JsonUtils.json(readConfigFile(RestConfiguration.DATASOURCE_FILENAME)))); RestConfiguration.setFactory(new LightblueFactory(RestConfiguration.getDatasources())); String expectedCreated = readFile("expectedCreated.json"); String metadata = readFile("metadata.json").replaceAll("ZZY", " UPDATE Country SET NAME=:name WHERE ISO2CODE=:ISO2CODE;"); EntityMetadata em = RestConfiguration.getFactory().getJSONParser() .parseEntityMetadata(JsonUtils.json(metadata)); RestConfiguration.getFactory().getMetadata().createNewMetadata(em); EntityMetadata em2 = RestConfiguration.getFactory().getMetadata().getEntityMetadata("country", "1.0.0"); String resultCreated = RestConfiguration.getFactory().getJSONParser().convert(em2).toString(); JSONAssert.assertEquals(expectedCreated, resultCreated, false); String expectedUpdated = readFile("expectedUpdated.json"); String resultUpdated = cutCrudResource.update("country", "1.0.0", readFile("resultUpdated.json")) .getEntity().toString(); System.err.println("!!!!!!!!!!!!!!!!!" + resultUpdated); ds = (DataSource) initCtx.lookup("java:/mydatasource"); conn = ds.getConnection(); stmt = conn.createStatement(); stmt.execute("SELECT * FROM Country;"); ResultSet resultSet = stmt.getResultSet(); resultSet.next(); Assert.assertEquals("Canada", resultSet.getString("name")); Assert.assertEquals("CA", resultSet.getString("iso2code")); Assert.assertEquals("c", resultSet.getString("iso3code")); JSONAssert.assertEquals(expectedUpdated, resultUpdated, false); } catch (NamingException | SQLException ex) { throw new IllegalStateException(ex); } mongo.dropDatabase(DB_NAME); }
From source file:org.exist.xquery.modules.sql.ExecuteFunction.java
/** * evaluate the call to the XQuery execute() function, it is really the main entry point of this class. * * @param args arguments from the execute() function call * @param contextSequence the Context Sequence to operate on (not used here internally!) * * @return A node representing the SQL result set * * @throws XPathException DOCUMENT ME! * * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence) *//* w ww. jav a 2 s . c o m*/ @Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { // was a connection and SQL statement specified? if (args[0].isEmpty() || args[1].isEmpty()) { return (Sequence.EMPTY_SEQUENCE); } // get the Connection long connectionUID = ((IntegerValue) args[0].itemAt(0)).getLong(); Connection con = SQLModule.retrieveConnection(context, connectionUID); if (con == null) { return (Sequence.EMPTY_SEQUENCE); } boolean preparedStmt = false; //setup the SQL statement String sql = null; Statement stmt = null; boolean executeResult = false; ResultSet rs = null; try { boolean makeNodeFromColumnName = false; MemTreeBuilder builder = context.getDocumentBuilder(); int iRow = 0; //SQL or PreparedStatement? if (args.length == 3) { // get the SQL statement sql = args[1].getStringValue(); stmt = con.createStatement(); makeNodeFromColumnName = ((BooleanValue) args[2].itemAt(0)).effectiveBooleanValue(); //execute the statement executeResult = stmt.execute(sql); } else if (args.length == 4) { preparedStmt = true; //get the prepared statement long statementUID = ((IntegerValue) args[1].itemAt(0)).getLong(); PreparedStatementWithSQL stmtWithSQL = SQLModule.retrievePreparedStatement(context, statementUID); sql = stmtWithSQL.getSql(); stmt = stmtWithSQL.getStmt(); makeNodeFromColumnName = ((BooleanValue) args[3].itemAt(0)).effectiveBooleanValue(); if (!args[2].isEmpty()) { setParametersOnPreparedStatement(stmt, (Element) args[2].itemAt(0)); } //execute the prepared statement executeResult = ((PreparedStatement) stmt).execute(); } else { //TODO throw exception } // DW: stmt can be null ? // execute the query statement if (executeResult) { /* SQL Query returned results */ // iterate through the result set building an XML document rs = stmt.getResultSet(); ResultSetMetaData rsmd = rs.getMetaData(); int iColumns = rsmd.getColumnCount(); builder.startDocument(); builder.startElement(new QName("result", SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); builder.addAttribute(new QName("count", null, null), String.valueOf(-1)); while (rs.next()) { builder.startElement(new QName("row", SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); builder.addAttribute(new QName("index", null, null), String.valueOf(rs.getRow())); // get each tuple in the row for (int i = 0; i < iColumns; i++) { String columnName = rsmd.getColumnLabel(i + 1); if (columnName != null) { String colElement = "field"; if (makeNodeFromColumnName && columnName.length() > 0) { // use column names as the XML node /** * Spaces in column names are replaced with * underscore's */ colElement = SQLUtils.escapeXmlAttr(columnName.replace(' ', '_')); } builder.startElement(new QName(colElement, SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); if (!makeNodeFromColumnName || columnName.length() <= 0) { String name; if (columnName.length() > 0) { name = SQLUtils.escapeXmlAttr(columnName); } else { name = "Column: " + String.valueOf(i + 1); } builder.addAttribute(new QName("name", null, null), name); } builder.addAttribute( new QName(TYPE_ATTRIBUTE_NAME, SQLModule.NAMESPACE_URI, SQLModule.PREFIX), rsmd.getColumnTypeName(i + 1)); builder.addAttribute(new QName(TYPE_ATTRIBUTE_NAME, Namespaces.SCHEMA_NS, "xs"), Type.getTypeName(SQLUtils.sqlTypeToXMLType(rsmd.getColumnType(i + 1)))); //get the content if (rsmd.getColumnType(i + 1) == Types.SQLXML) { //parse sqlxml value try { final SQLXML sqlXml = rs.getSQLXML(i + 1); if (rs.wasNull()) { // Add a null indicator attribute if the value was SQL Null builder.addAttribute( new QName("null", SQLModule.NAMESPACE_URI, SQLModule.PREFIX), "true"); } else { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); InputSource src = new InputSource(sqlXml.getCharacterStream()); SAXParser parser = factory.newSAXParser(); XMLReader xr = parser.getXMLReader(); SAXAdapter adapter = new AppendingSAXAdapter(builder); xr.setContentHandler(adapter); xr.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter); xr.parse(src); } } catch (Exception e) { throw new XPathException( "Could not parse column of type SQLXML: " + e.getMessage(), e); } } else { //otherwise assume string value final String colValue = rs.getString(i + 1); if (rs.wasNull()) { // Add a null indicator attribute if the value was SQL Null builder.addAttribute( new QName("null", SQLModule.NAMESPACE_URI, SQLModule.PREFIX), "true"); } else { if (colValue != null) { builder.characters(SQLUtils.escapeXmlText(colValue)); } } } builder.endElement(); } } builder.endElement(); iRow++; } builder.endElement(); } else { /* SQL Query performed updates */ builder.startDocument(); builder.startElement(new QName("result", SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); builder.addAttribute(new QName("updateCount", null, null), String.valueOf(stmt.getUpdateCount())); builder.endElement(); } // Change the root element count attribute to have the correct value NodeValue node = (NodeValue) builder.getDocument().getDocumentElement(); Node count = node.getNode().getAttributes().getNamedItem("count"); if (count != null) { count.setNodeValue(String.valueOf(iRow)); } builder.endDocument(); // return the XML result set return (node); } catch (SQLException sqle) { LOG.error("sql:execute() Caught SQLException \"" + sqle.getMessage() + "\" for SQL: \"" + sql + "\"", sqle); //return details about the SQLException MemTreeBuilder builder = context.getDocumentBuilder(); builder.startDocument(); builder.startElement(new QName("exception", SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); boolean recoverable = false; if (sqle instanceof SQLRecoverableException) { recoverable = true; } builder.addAttribute(new QName("recoverable", null, null), String.valueOf(recoverable)); builder.startElement(new QName("state", SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); builder.characters(sqle.getSQLState()); builder.endElement(); builder.startElement(new QName("message", SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); String state = sqle.getMessage(); if (state != null) { builder.characters(state); } builder.endElement(); builder.startElement(new QName("stack-trace", SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); ByteArrayOutputStream bufStackTrace = new ByteArrayOutputStream(); sqle.printStackTrace(new PrintStream(bufStackTrace)); builder.characters(new String(bufStackTrace.toByteArray())); builder.endElement(); builder.startElement(new QName("sql", SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); builder.characters(SQLUtils.escapeXmlText(sql)); builder.endElement(); if (stmt instanceof PreparedStatement) { Element parametersElement = (Element) args[2].itemAt(0); if (parametersElement.getNamespaceURI().equals(SQLModule.NAMESPACE_URI) && parametersElement.getLocalName().equals(PARAMETERS_ELEMENT_NAME)) { NodeList paramElements = parametersElement.getElementsByTagNameNS(SQLModule.NAMESPACE_URI, PARAM_ELEMENT_NAME); builder.startElement( new QName(PARAMETERS_ELEMENT_NAME, SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); for (int i = 0; i < paramElements.getLength(); i++) { Element param = ((Element) paramElements.item(i)); String value = param.getFirstChild().getNodeValue(); String type = param.getAttributeNS(SQLModule.NAMESPACE_URI, TYPE_ATTRIBUTE_NAME); builder.startElement( new QName(PARAM_ELEMENT_NAME, SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); builder.addAttribute( new QName(TYPE_ATTRIBUTE_NAME, SQLModule.NAMESPACE_URI, SQLModule.PREFIX), type); builder.characters(SQLUtils.escapeXmlText(value)); builder.endElement(); } builder.endElement(); } } builder.startElement(new QName("xquery", SQLModule.NAMESPACE_URI, SQLModule.PREFIX), null); builder.addAttribute(new QName("line", null, null), String.valueOf(getLine())); builder.addAttribute(new QName("column", null, null), String.valueOf(getColumn())); builder.endElement(); builder.endElement(); builder.endDocument(); return ((NodeValue) builder.getDocument().getDocumentElement()); } finally { // close any record set or statement if (rs != null) { try { rs.close(); } catch (SQLException se) { LOG.warn("Unable to cleanup JDBC results", se); } rs = null; } if (!preparedStmt && stmt != null) { try { stmt.close(); } catch (SQLException se) { LOG.warn("Unable to cleanup JDBC results", se); } stmt = null; } } }
From source file:mom.trd.opentheso.bdd.helper.CandidateHelper.java
/** * Cette fonction permet de retourner le nombre de candidats d'un concept * * @param ds/*w w w .j a v a 2 s . c o m*/ * @param idConcept * @param idThesaurus * @return Objet class NodeConceptTree */ public int getNbPropCandidat(HikariDataSource ds, String idThesaurus, String idConcept) { Connection conn; Statement stmt; ResultSet resultSet; int count = 0; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select count(id_concept) from proposition where" + " id_concept = '" + idConcept + "'" + " AND id_thesaurus = '" + idThesaurus + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { resultSet.next(); if (resultSet.getInt(1) != 0) { count = resultSet.getInt(1); } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting count of candidat of Concept : " + idConcept, sqle); } return count; }
From source file:org.apache.hive.jdbc.TestJdbcDriver2.java
@Test public void testShowGrant() throws SQLException { Statement stmt = con.createStatement(); stmt.execute("grant select on table " + dataTypeTableName + " to user hive_test_user"); stmt.execute("show grant user hive_test_user on table " + dataTypeTableName); ResultSet res = stmt.getResultSet(); assertTrue(res.next());/*from w w w . j a va 2 s . c o m*/ assertEquals("default", res.getString(1)); assertEquals(dataTypeTableName, res.getString(2)); assertEquals("", res.getString(3)); // partition assertEquals("", res.getString(4)); // column assertEquals("hive_test_user", res.getString(5)); assertEquals("USER", res.getString(6)); assertEquals("SELECT", res.getString(7)); assertEquals(false, res.getBoolean(8)); // grant option assertEquals(-1, res.getLong(9)); assertNotNull(res.getString(10)); // grantor assertFalse(res.next()); res.close(); }
From source file:mom.trd.opentheso.bdd.helper.CandidateHelper.java
/** * Cette fonction permet de mettre jour le status d'un candidat * //from w w w .j a v a 2s. c om * @param ds * @param idConceptCandidat * @param idThesaurus * @return idTermCandidat */ public String getIdTermOfConceptCandidat(HikariDataSource ds, String idConceptCandidat, String idThesaurus) { Connection conn; Statement stmt; ResultSet resultSet; String idTermCandidat = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT id_term" + " FROM concept_term_candidat" + " WHERE id_thesaurus = '" + idThesaurus + "'" + " and id_concept = '" + idConceptCandidat + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet.next()) { idTermCandidat = resultSet.getString("id_term"); } else return null; } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting idTermCandidat of idConceptCandidat : " + idConceptCandidat, sqle); } return idTermCandidat; }
From source file:mom.trd.opentheso.bdd.helper.GroupHelper.java
/** * Cette fonction permet de rcuprer la liste des domaines sauf celui en * cours pour l'autocompltion//ww w . j a v a 2 s .c om * * @param ds * @param idThesaurus * @param idGroup * @param text * @param idLang * @return Objet class Concept */ public List<NodeAutoCompletion> getAutoCompletionOtherGroup(HikariDataSource ds, String idThesaurus, String idGroup, // le Group ignorer String idLang, String text) { Connection conn; Statement stmt; ResultSet resultSet; List<NodeAutoCompletion> nodeAutoCompletionList = null; text = new StringPlus().convertString(text); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT concept_group_label.idgroup," + " concept_group_label.lexicalvalue FROM concept_group_label" + " WHERE " + " concept_group_label.idthesaurus = '" + idThesaurus + "'" + " AND concept_group_label.lang = '" + idLang + "'" + " AND concept_group_label.idgroup != '" + idGroup + "'" + " AND unaccent_string(concept_group_label.lexicalvalue) ILIKE unaccent_string('" + text + "%')" + " ORDER BY concept_group_label.lexicalvalue ASC LIMIT 20"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); nodeAutoCompletionList = new ArrayList<>(); while (resultSet.next()) { if (resultSet.getRow() != 0) { NodeAutoCompletion nodeAutoCompletion = new NodeAutoCompletion(); nodeAutoCompletion.setIdConcept(""); nodeAutoCompletion.setTermLexicalValue(""); nodeAutoCompletion.setGroupLexicalValue(resultSet.getString("lexicalvalue")); nodeAutoCompletion.setIdGroup(resultSet.getString("idgroup")); nodeAutoCompletionList.add(nodeAutoCompletion); } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting List of autocompletion of Text : " + text, sqle); } return nodeAutoCompletionList; }
From source file:org.apache.zeppelin.hopshive.HopsHiveInterpreter.java
private InterpreterResult executeSql(String propertyKey, String sql, InterpreterContext interpreterContext) { Connection connection;/*from ww w . j a v a 2s.com*/ Statement statement; ResultSet resultSet = null; String paragraphId = interpreterContext.getParagraphId(); String user = interpreterContext.getAuthenticationInfo().getUser(); boolean splitQuery = false; String splitQueryProperty = getProperty(String.format("%s.%s", propertyKey, SPLIT_QURIES_KEY)); if (StringUtils.isNotBlank(splitQueryProperty) && splitQueryProperty.equalsIgnoreCase("true")) { splitQuery = true; } InterpreterResult interpreterResult = new InterpreterResult(InterpreterResult.Code.SUCCESS); try { connection = getConnection(propertyKey, interpreterContext); if (connection == null) { return new InterpreterResult(Code.ERROR, "Prefix not found."); } List<String> sqlArray; if (splitQuery) { sqlArray = splitSqlQueries(sql); } else { sqlArray = Arrays.asList(sql); } for (int i = 0; i < sqlArray.size(); i++) { String sqlToExecute = sqlArray.get(i); statement = connection.createStatement(); // fetch n+1 rows in order to indicate there's more rows available (for large selects) statement.setFetchSize(getMaxResult()); statement.setMaxRows(getMaxResult() + 1); if (statement == null) { return new InterpreterResult(Code.ERROR, "Prefix not found."); } try { getJDBCConfiguration(user).saveStatement(paragraphId, statement); boolean isResultSetAvailable = statement.execute(sqlToExecute); getJDBCConfiguration(user).setConnectionInDBDriverPoolSuccessful(propertyKey); if (isResultSetAvailable) { resultSet = statement.getResultSet(); // Regards that the command is DDL. if (isDDLCommand(statement.getUpdateCount(), resultSet.getMetaData().getColumnCount())) { interpreterResult.add(InterpreterResult.Type.TEXT, "Query executed successfully."); } else { String results = getResults(resultSet, !containsIgnoreCase(sqlToExecute, EXPLAIN_PREDICATE)); interpreterResult.add(results); if (resultSet.next()) { interpreterResult.add(ResultMessages.getExceedsLimitRowsMessage(getMaxResult(), String.format("%s.%s", COMMON_KEY, MAX_LINE_KEY))); } } } else { // Response contains either an update count or there are no results. int updateCount = statement.getUpdateCount(); interpreterResult.add(InterpreterResult.Type.TEXT, "Query executed successfully. Affected rows : " + updateCount); } } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { /*ignored*/ } } if (statement != null) { try { statement.close(); } catch (SQLException e) { /*ignored*/ } } } } //In case user ran an insert/update/upsert statement if (connection != null) { try { if (!connection.getAutoCommit()) { connection.commit(); } } catch (SQLException e) { /*ignored*/ } } getJDBCConfiguration(user).removeStatement(paragraphId); } catch (Throwable e) { logger.error("Cannot run " + sql, e); String errorMsg = Throwables.getStackTraceAsString(e); interpreterResult.add(errorMsg); return new InterpreterResult(Code.ERROR, interpreterResult.message()); } return interpreterResult; }
From source file:mom.trd.opentheso.bdd.helper.CandidateHelper.java
/** * Cette fonction permet de savoir si le Candidat existe ou non * @param ds/* ww w . j a v a2 s .c o m*/ * @param title * @param idThesaurus * @param idLang * @return boolean */ public boolean isCandidatExist(HikariDataSource ds, String title, String idThesaurus, String idLang) { Connection conn; Statement stmt; ResultSet resultSet; boolean existe = false; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select id_term from term_candidat where " + "unaccent_string(lexical_value) ilike " + "unaccent_string('" + title + "') and lang = '" + idLang + "' and id_thesaurus = '" + idThesaurus + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet.next()) { existe = resultSet.getRow() != 0; } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while asking if Title of Candidat exist : " + title, sqle); } return existe; }
From source file:mom.trd.opentheso.bdd.helper.CandidateHelper.java
/** * Permet de retourner une ArrayList de NodeConceptCandidat par * thsaurus, c'est la liste des candidats en attente (status = a) * Si le Candidat n'est pas traduit dans la langue en cours, on rcupre * l'identifiant pour l'afficher la place * * @param ds le pool de connexion/*from w w w. j a v a2s. c o m*/ * @param idThesaurus * @param idLang * @return Objet Class ArrayList NodeCandidatValue */ public ArrayList<NodeCandidatValue> getListCandidatsWaiting(HikariDataSource ds, String idThesaurus, String idLang) { Connection conn; Statement stmt; ResultSet resultSet; ArrayList<NodeCandidatValue> nodeCandidatLists = null; ArrayList tabIdConcept = new ArrayList(); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select id_concept from concept_candidat where id_thesaurus = '" + idThesaurus + "'" + " and status ='a' order by modified DESC"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); while (resultSet.next()) { tabIdConcept.add(resultSet.getString("id_concept")); } nodeCandidatLists = new ArrayList<>(); for (Object tabIdConcept1 : tabIdConcept) { NodeCandidatValue nodeCandidatValue; nodeCandidatValue = getThisCandidat(ds, tabIdConcept1.toString(), idThesaurus, idLang); if (nodeCandidatValue == null) return null; nodeCandidatValue.setEtat("a"); nodeCandidatValue.setNbProp(getNbPropCandidat(ds, idThesaurus, tabIdConcept1.toString())); nodeCandidatLists.add(nodeCandidatValue); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting List Group or Domain of thesaurus : " + idThesaurus, sqle); } return nodeCandidatLists; }