Example usage for java.sql Statement getResultSet

List of usage examples for java.sql Statement getResultSet

Introduction

In this page you can find the example usage for java.sql Statement getResultSet.

Prototype

ResultSet getResultSet() throws SQLException;

Source Link

Document

Retrieves the current result as a ResultSet object.

Usage

From source file:mom.trd.opentheso.bdd.helper.TermHelper.java

/**
 * Cette fonction permet de rcuprer une liste des terms pour
 * l'autocompltion en se limitant  un Group
 * et en ignorant le terme lui mme//from   w  ww  .  ja v a  2 s .com
 *
 * @param ds
 * @param idSelectedConcept
 * @param idThesaurus
 * @param text
 * @param idGroup
 * @param idLang
 * @return Objet class Concept
 */
public List<NodeAutoCompletion> getAutoCompletionTerm(HikariDataSource ds, String idSelectedConcept, // le concept  ignorer
        String idThesaurus, String idLang, String idGroup, String text) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    List<NodeAutoCompletion> nodeAutoCompletionList = new ArrayList<>();
    text = new StringPlus().convertString(text);

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT DISTINCT term.lexical_value, concept.id_concept, concept.id_group "
                        + "FROM preferred_term, term, concept WHERE "
                        + "preferred_term.id_term = term.id_term AND "
                        + "preferred_term.id_thesaurus = term.id_thesaurus AND "
                        + "concept.id_concept = preferred_term.id_concept AND "
                        + "concept.id_thesaurus = preferred_term.id_thesaurus AND " + "term.id_thesaurus = '"
                        + idThesaurus + "' AND " + "term.lang = '" + idLang + "' AND " + "concept.id_group = '"
                        + idGroup + "' AND " + "concept.id_concept != '" + idSelectedConcept + "' AND "
                        + "concept.status != 'hidden' AND "
                        + "unaccent_string(term.lexical_value) ILIKE unaccent_string('" + text + "%')"
                        + " ORDER BY term.lexical_value ASC LIMIT 20";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {

                    while (resultSet.next()) {
                        if (resultSet.getRow() != 0) {
                            NodeAutoCompletion nodeAutoCompletion = new NodeAutoCompletion();

                            nodeAutoCompletion.setIdConcept(resultSet.getString("id_concept"));
                            nodeAutoCompletion.setTermLexicalValue(resultSet.getString("lexical_value"));
                            nodeAutoCompletion.setGroupLexicalValue(new GroupHelper().getLexicalValueOfGroup(ds,
                                    resultSet.getString("id_group"), idThesaurus, idLang));
                            nodeAutoCompletion.setIdGroup(resultSet.getString("id_group"));
                            //  if(!nodeAutoCompletionList.contains(nodeAutoCompletion))
                            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:mom.trd.opentheso.bdd.helper.TermHelper.java

/**
 * Cette fonction permet de rcuprer une liste des terms pour
 * l'autocompltion en se vitant le Group actuel
 * et en ignorant le terme lui mme/*from w  ww  . j a v a  2  s  . c o m*/
 *
 * @param ds
 * @param idSelectedConcept
 * @param idThesaurus
 * @param text
 * @param idGroup
 * @param idLang
 * @return Objet class Concept
 */
public List<NodeAutoCompletion> getAutoCompletionTermOfOtherGroup(HikariDataSource ds, String idSelectedConcept, // le concept  ignorer
        String idThesaurus, String idLang, String idGroup, String text) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    List<NodeAutoCompletion> nodeAutoCompletionList = new ArrayList<>();
    text = new StringPlus().convertString(text);

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT DISTINCT term.lexical_value, concept.id_concept, concept.id_group "
                        + "FROM preferred_term, term, concept WHERE "
                        + "preferred_term.id_term = term.id_term AND "
                        + "preferred_term.id_thesaurus = term.id_thesaurus AND "
                        + "concept.id_concept = preferred_term.id_concept AND "
                        + "concept.id_thesaurus = preferred_term.id_thesaurus AND " + "term.id_thesaurus = '"
                        + idThesaurus + "' AND " + "term.lang = '" + idLang + "' AND " + "concept.id_group != '"
                        + idGroup + "' AND " + "concept.id_concept != '" + idSelectedConcept + "' AND "
                        + "concept.status != 'hidden' AND "
                        + "unaccent_string(term.lexical_value) ILIKE unaccent_string('" + text + "%')"
                        + " ORDER BY term.lexical_value ASC LIMIT 20";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {

                    while (resultSet.next()) {
                        if (resultSet.getRow() != 0) {
                            NodeAutoCompletion nodeAutoCompletion = new NodeAutoCompletion();

                            nodeAutoCompletion.setIdConcept(resultSet.getString("id_concept"));
                            nodeAutoCompletion.setTermLexicalValue(resultSet.getString("lexical_value"));
                            nodeAutoCompletion.setGroupLexicalValue(new GroupHelper().getLexicalValueOfGroup(ds,
                                    resultSet.getString("id_group"), idThesaurus, idLang));
                            nodeAutoCompletion.setIdGroup(resultSet.getString("id_group"));
                            //  if(!nodeAutoCompletionList.contains(nodeAutoCompletion))
                            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:mom.trd.opentheso.bdd.helper.TermHelper.java

/**
 * Cette fonction permet de rcuprer une liste des terms pour
 * l'autocompltion en se limitant  un Group
 * et en ignorant le terme lui mme et ses BT
 *
 * @param ds/*from  w w w  .  java2  s.com*/
 * @param idSelectedConcept
 * @param idBT
 * @param idThesaurus
 * @param text
 * @param idGroup
 * @param idLang
 * @return Objet class Concept
 */
public List<NodeAutoCompletion> getAutoCompletionTerm(HikariDataSource ds, String idSelectedConcept,
        ArrayList<String> idBTs, // le concept  ignorer
        String idThesaurus, String idLang, String idGroup, String text) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    List<NodeAutoCompletion> nodeAutoCompletionList = new ArrayList<>();
    text = new StringPlus().convertString(text);

    String BT = "";
    for (String idBt : idBTs) {
        if (!BT.isEmpty()) {
            BT = BT + ",'" + idBt + "'";
        } else
            BT = "'" + idBt + "'";
    }

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT DISTINCT term.lexical_value, concept.id_concept, concept.id_group "
                        + "FROM preferred_term, term, concept WHERE "
                        + "preferred_term.id_term = term.id_term AND "
                        + "preferred_term.id_thesaurus = term.id_thesaurus AND "
                        + "concept.id_concept = preferred_term.id_concept AND "
                        + "concept.id_thesaurus = preferred_term.id_thesaurus AND " + "term.id_thesaurus = '"
                        + idThesaurus + "' AND " + "term.lang = '" + idLang + "' AND " + "concept.id_group = '"
                        + idGroup + "' AND " + "concept.id_concept != '" + idSelectedConcept + "' AND "
                        + "concept.id_concept not in (" + BT + ") AND " + "concept.status != 'hidden' AND "
                        + "unaccent_string(term.lexical_value) ILIKE unaccent_string('" + text + "%')"
                        + " ORDER BY term.lexical_value ASC LIMIT 20";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {

                    while (resultSet.next()) {
                        if (resultSet.getRow() != 0) {
                            NodeAutoCompletion nodeAutoCompletion = new NodeAutoCompletion();

                            nodeAutoCompletion.setIdConcept(resultSet.getString("id_concept"));
                            nodeAutoCompletion.setTermLexicalValue(resultSet.getString("lexical_value"));
                            nodeAutoCompletion.setGroupLexicalValue(new GroupHelper().getLexicalValueOfGroup(ds,
                                    resultSet.getString("id_group"), idThesaurus, idLang));
                            nodeAutoCompletion.setIdGroup(resultSet.getString("id_group"));
                            //  if(!nodeAutoCompletionList.contains(nodeAutoCompletion))
                            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:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de savoir si l'ID du concept existe ou non
 *
 * @param conn//from  w  ww.j  ava2  s  .c om
 * @param idConcept
 * @return boolean
 */
public boolean isIdExiste(Connection conn, String idConcept) {

    Statement stmt;
    ResultSet resultSet;
    boolean existe = false;

    try {
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept from concept where " + "id_concept = '" + idConcept + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next()) {
                    existe = resultSet.getRow() != 0;
                }

            } finally {
                stmt.close();
            }
        } finally {
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while asking if id exist : " + idConcept, sqle);
    }
    return existe;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer l'identifiant du Concept d'aprs
 * l'idArk//w  w w  .j av  a2 s  .  co  m
 *
 * @param ds
 * @param arkId
 * @return IdConcept
 */
public String getIdConceptFromArkId(HikariDataSource ds, String arkId) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    String idConcept = null;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept from concept where" + " id_ark = '" + arkId + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();

                if (resultSet.next()) {
                    idConcept = resultSet.getString("id_concept");
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting idConcept by idArk : " + arkId, sqle);
    }
    return idConcept;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer l'identifiant du Concept d'aprs
 * l'idArk//from  www.  j  a va  2s  . com
 *
 * @param ds
 * @param arkId
 * @return IdConcept
 */
public String getIdThesaurusFromArkId(HikariDataSource ds, String arkId) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    String idThesaurus = null;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_thesaurus from concept where" + " id_ark = '" + arkId + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();

                if (resultSet.next()) {
                    idThesaurus = resultSet.getString("id_thesaurus");
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting idThesaurus by idArk : " + arkId, sqle);
    }
    return idThesaurus;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de savoir si l'ID du concept existe ou non
 *
 * @param conn//from w w w.  java  2 s. c  o  m
 * @param idConcept
 * @param idThesaurus
 * @return boolean
 */
public boolean isIdExiste(Connection conn, String idConcept, String idThesaurus) {

    Statement stmt;
    ResultSet resultSet;
    boolean existe = false;

    try {
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept from concept where " + "id_concept = '" + idConcept
                        + "' and id_thesaurus = '" + idThesaurus + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next()) {
                    existe = resultSet.getRow() != 0;
                }

            } finally {
                stmt.close();
            }
        } finally {
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while asking if id exist : " + idConcept, sqle);
    }
    return existe;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer l'identifiant Ark sinon renvoie un une
 * chaine vide/*from  w w  w .  j  a v  a2s  . c o m*/
 *
 * @param ds
 * @param idConcept
 * @param idThesaurus
 * @return Objet class Concept
 */
public String getIdArkOfConcept(HikariDataSource ds, String idConcept, String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    String ark = "";
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_ark from concept where" + " id_thesaurus = '" + idThesaurus + "'"
                        + " and id_concept = '" + idConcept + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();

                if (resultSet.next()) {

                    ark = resultSet.getString("id_ark");
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting idArk of Concept : " + idConcept, sqle);
    }
    return ark;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer la liste des Id concept d'un thsaurus
 * (cette fonction sert pour la gnration de la table Permut
 *
 * @param ds//ww  w.ja  v a  2 s .  co m
 * @param idThesaurus
 * @return ArrayList
 */
public ArrayList<String> getAllIdConceptOfThesaurus(HikariDataSource ds, String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<String> tabIdConcept = new ArrayList<>();

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept from concept where id_thesaurus = '" + idThesaurus + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();

                while (resultSet.next()) {
                    tabIdConcept.add(resultSet.getString("id_concept"));
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting All IdConcept of Thesaurus : " + idThesaurus, sqle);
    }
    return tabIdConcept;
}

From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer la date de modificatin du Concept
 *
 * @param ds//from w w  w. j  av a  2  s  . c  o  m
 * @param idConcept
 * @param idThesaurus
 * @return Objet class Concept
 */
public Date getModifiedDateOfConcept(HikariDataSource ds, String idConcept, String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    Date date = null;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select modified from concept where id_thesaurus = '" + idThesaurus + "'"
                        + " and id_concept = '" + idConcept + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                resultSet.next();
                if (resultSet.getRow() != 0) {
                    date = resultSet.getDate("modified");
                }
                resultSet.close();

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting modified date of Concept : " + idConcept, sqle);
    }
    return date;
}