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.ConceptHelper.java

/**
 * Cette fonction permet de rcuprer l'identifiant du Group d'un Concept
 *
 * @param ds//from  ww  w . jav  a2s .co  m
 * @param idConcept
 * @param idThesaurus
 * @return String idGroup
 */
public String getGroupIdOfConcept(HikariDataSource ds, String idConcept, String idThesaurus) {

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

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

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

/**
 * Cette fonction permet de savoir si l'ID du concept existe ou non
 *
 * @param ds/*from   ww  w .  ja  v  a  2s  .com*/
 * @param idConcept
 * @param idThesaurus
 * @return boolean
 */
public boolean isIdExiste(HikariDataSource ds, String idConcept, String idThesaurus) {

    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_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 {
            conn.close();
        }
    } 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 un Concept par son id et son thsaurus
 * sous forme de classe Concept (sans les relations) ni le Terme
 *
 * @param ds//from w  w  w.  java 2s. c  o m
 * @param idConcept
 * @param idThesaurus
 * @return Objet class Concept
 */
public Concept getThisConcept(HikariDataSource ds, String idConcept, String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    Concept concept = null;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select * from concept where id_thesaurus = '" + idThesaurus + "'"
                        + " and id_concept = '" + idConcept + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                resultSet.next();
                if (resultSet.getRow() != 0) {
                    concept = new Concept();
                    concept.setIdConcept(idConcept);
                    concept.setIdThesaurus(idThesaurus);
                    concept.setIdArk(resultSet.getString("id_ark"));
                    concept.setCreated(resultSet.getDate("created"));
                    concept.setModified(resultSet.getDate("modified"));
                    concept.setStatus(resultSet.getString("status"));
                    concept.setNotation(resultSet.getString("notation"));
                    concept.setTopConcept(resultSet.getBoolean("top_concept"));
                    concept.setIdGroup(resultSet.getString("id_group"));
                }
                resultSet.close();

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

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

public String getPereConcept(HikariDataSource ds, String id_theso, String id_concept) {
    String conceptPere = "";
    Connection conn;/*from   w  ww  .j  a  v a 2s . c o m*/
    Statement stmt;
    ResultSet resultSet;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT id_concept2 FROM hierarchical_relationship" + " WHERE id_thesaurus='"
                        + id_theso + "'" + " AND id_concept1='" + id_concept + "'" + " AND role ='BT'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next())
                    conceptPere = resultSet.getString("id_concept2");
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while get le pere du concept : " + id_concept, sqle);
    }
    return conceptPere;
}

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 .jav a 2 s . com
 * @param idThesaurus
 * @param notation
 * @return boolean
 */
public boolean isNotationExist(Connection conn, String idThesaurus, String notation) {

    Statement stmt;
    ResultSet resultSet;
    boolean existe = false;

    if (notation.isEmpty()) {
        return false;
    }
    try {
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept from concept where " + " id_thesaurus = '" + idThesaurus + "'"
                        + " and notation ilike '" + notation.trim() + "'";
                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 Notation exist : " + notation, sqle);
    }
    return existe;
}

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

/**
 * Cette fonction permet de savoir si le Concept est un TopConcept sans
 * dfinir le group (pour permettre de nettoyer les orphelins)
 *
 * @param ds/*from  w w  w  .j a  va  2s  .  c om*/
 * @param idConcept
 * @param idThesaurus
 * @return boolean
 */
public boolean isTopConcept(HikariDataSource ds, String idConcept, String idThesaurus) {

    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 top_concept from concept where " + " id_concept = '" + idConcept + "'"
                        + " and id_thesaurus = '" + idThesaurus + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next()) {
                    existe = resultSet.getBoolean("top_concept");
                }

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

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

/**
 * Cette fonction permet de retourner l'id du Concept d'aprs un idTerm
 *
 * @param ds/*ww  w. ja v a 2  s.c o m*/
 * @param idTerm
 * @param idThesaurus
 * @return idConcept
 */
public String getIdConceptOfTerm(HikariDataSource ds, String idTerm, String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    String idConcept = null;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT id_concept FROM" + " preferred_term WHERE" + " id_thesaurus = '"
                        + idThesaurus + "'" + " and id_term = '" + idTerm + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next()) {
                    idConcept = resultSet.getString("id_concept");
                } else {
                    return null;
                }

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

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

/**
 * Cette fonction permet de rcuprer les identifiants des Group d'un
 * Concept//from  w  ww .  j  a  v a2s  .c o m
 *
 * @param ds
 * @param idConcept
 * @param idThesaurus
 * @return String idGroup
 */
public ArrayList<String> getListGroupIdOfConcept(HikariDataSource ds, String idConcept, String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<String> idGroup = new ArrayList<>();
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_group from concept where id_thesaurus = '" + idThesaurus + "'"
                        + " and id_concept = '" + idConcept + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    while (resultSet.next()) {
                        idGroup.add(resultSet.getString("id_group"));
                    }
                }

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

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

public boolean haveThisGroup(HikariDataSource ds, String idConcept, String idDomaine, String idTheso) {
    Connection conn;/*from  w  w w.j  a  v  a2s  . co m*/
    Statement stmt;
    ResultSet resultSet;
    boolean group = false;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT id_concept FROM concept" + " WHERE id_thesaurus='" + idTheso + "'"
                        + " AND id_concept='" + idConcept + "'" + " AND id_group='" + idDomaine + "'";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                resultSet.next();
                group = (resultSet.getRow() != 0);

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

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

/**
 * Cette fonction permet de savoir si le Concept est un TopConcept
 *
 * @param ds//from w  w  w  . j  av  a2 s  . c om
 * @param idConcept
 * @param idThesaurus
 * @param idGroup
 * @return boolean
 */
public boolean isTopConcept(HikariDataSource ds, String idConcept, String idThesaurus, String idGroup) {

    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 top_concept from concept where " + " id_concept = '" + idConcept + "'"
                        + " and id_thesaurus = '" + idThesaurus + "'" + " and id_group = '" + idGroup + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next()) {
                    existe = resultSet.getBoolean("top_concept");
                }

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