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:je3.rmi.MudClient.java

 /** Get the transaction history of the named account */
 public synchronized List getTransactionHistory(String name, 
                  String password)
throws RemoteException, BankingException
 {
     Statement s = null;
     List list = new ArrayList();
     try {/*from  ww w . j  a v a  2 s .c  o  m*/
         // Call verify to check the password, even though we don't 
         // care what the current balance is.
         verify(name, password);
         s = db.createStatement();
         // Request everything out of the history table
         s.executeQuery("SELECT * from " + name + "_history");
         // Get the results of the query and put them in a Vector
         ResultSet r = s.getResultSet();
         while(r.next()) list.add(r.getString(1));
         // Commit the transaction
         db.commit();
     }
     catch (SQLException e) {
         try { db.rollback(); } catch (Exception e2) {}
         throw new BankingException("SQLException: " + e.getMessage() + 
                ": " + e.getSQLState());
     }
     finally { try { s.close(); } catch (Exception e) {} }
     // Return the Vector of transaction history.
     return list;
 }

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

/**
 * cette fonction est pour trier les concept NT par date chronologique
 *
 * @param ds//from  w  ww  . j  a v a  2s .com
 * @param idConcept
 * @param idThesaurus
 * @param idLang
 * @return
 */
public ArrayList<NodeNT> getListNTOrderByDate(HikariDataSource ds, String idConcept, String idThesaurus,
        String idLang) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeNT> nodeListNT = new ArrayList<>();

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select hierarchical_relationship.id_concept2, concept.modified "
                        + " FROM concept, hierarchical_relationship" + " where concept.id_thesaurus = '"
                        + idThesaurus + "'"
                        + " and hierarchical_relationship.id_thesaurus = concept.id_thesaurus "
                        + " and concept.id_concept = hierarchical_relationship.id_concept2 "
                        + " and id_concept1 = '" + idConcept + "'" + " and role = '" + "NT" + "'"
                        + " order by modified DESC";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    while (resultSet.next()) {
                        NodeNT nodeNT = new NodeNT();
                        nodeNT.setIdConcept(resultSet.getString("id_concept2"));
                        nodeListNT.add(nodeNT);
                    }
                }
                for (NodeNT nodeNT : nodeListNT) {
                    query = "SELECT term.lexical_value, term.status FROM term, preferred_term"
                            + " WHERE preferred_term.id_term = term.id_term"
                            + " and preferred_term.id_thesaurus = term.id_thesaurus"
                            + " and preferred_term.id_concept ='" + nodeNT.getIdConcept() + "'"
                            + " and term.lang = '" + idLang + "'" + " and term.id_thesaurus = '" + idThesaurus
                            + "'";

                    stmt.executeQuery(query);
                    resultSet = stmt.getResultSet();
                    if (resultSet != null) {
                        resultSet.next();
                        if (resultSet.getRow() == 0) {
                            nodeNT.setTitle("");
                            nodeNT.setStatus("");
                        } else {
                            if (resultSet.getString("lexical_value") == null
                                    || resultSet.getString("lexical_value").equals("")) {
                                nodeNT.setTitle("");
                            } else {
                                nodeNT.setTitle(resultSet.getString("lexical_value"));
                            }
                            if (resultSet.getString("status") == null
                                    || resultSet.getString("status").equals("")) {
                                nodeNT.setStatus("");
                            } else {
                                nodeNT.setStatus(resultSet.getString("status"));
                            }
                        }
                    }
                }

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

    return nodeListNT;
}

From source file:com.hangum.tadpole.rdb.core.editors.main.composite.ResultSetComposite.java

/**
 * select? .//from w ww .jav a2s.c o  m
 * 
 * @param strSQL
 */
private ResultSet _runSQLSelect(final Statement statement, final String strSQL) throws Exception {

    Future<ResultSet> queryFuture = execServiceQuery.submit(new Callable<ResultSet>() {
        @Override
        public ResultSet call() throws SQLException {

            // ???  PL/SQL  dbms_output    ? .
            if (DBGroupDefine.ORACLE_GROUP == getUserDB().getDBGroup()) {
                try {
                    dbmsOutput = new OracleDbmsOutputUtil(statement.getConnection());
                    dbmsOutput.enable(1000000);
                    statement.execute(strSQL);
                    dbmsOutput.show();
                    tadpole_system_message = dbmsOutput.getOutput();
                } finally {
                    try {
                        if (dbmsOutput != null)
                            dbmsOutput.close();
                    } catch (SQLException e) {
                    }
                }
            } else {
                statement.execute(strSQL);
            }

            return statement.getResultSet();
        }
    });

    /* SELECT ALRM_DATE ? select??  ?? ?  ? ? ?.
     * Caused by: java.lang.NullPointerException
       at oracle.jdbc.driver.T4C8Oall.getNumRows(T4C8Oall.java:973)
     */
    return queryFuture.get();
}

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

/**
 * Cette fonction permet d'ajouter un Concept  la table Concept, en
 * paramtre un objet Classe Concept//from  w  ww.  j a  va2  s . c  o m
 *
 * @param ds
 * @param idThesaurus
 * @return idConceptCandidat 
 */
public String addConceptCandidat(HikariDataSource ds, String idThesaurus) {

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

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select max(id) from concept_candidat";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                resultSet.next();
                int idNumerique = resultSet.getInt(1);
                idConcept = "CA_" + (++idNumerique);
                while (isCandidatExist(ds.getConnection(), idConcept, idThesaurus)) {
                    idConcept = "CA_" + (++idNumerique);
                }

                /**
                 * Ajout des informations dans la table Concept_candidat
                 */
                query = "Insert into concept_candidat " + "(id_concept, id_thesaurus)" + " values (" + "'"
                        + idConcept + "'" + ",'" + idThesaurus + "')";

                stmt.executeUpdate(query);

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

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

/**
 * Cette fonction permet de rajouter un term_candidat 
 * /*w w w . jav a 2  s  .c  om*/
 * @param conn
 * @param lexical_value
 * @param idLang
 * @param idThesaurus
 * @param contributor
 * @return  idConceptCandidat
 */
public String addTermCandidat_RollBack(Connection conn, String lexical_value, String idLang, String idThesaurus,
        int contributor) {

    Statement stmt;
    ResultSet resultSet;
    String idTerm = null;
    lexical_value = new StringPlus().convertString(lexical_value);
    try {
        try {
            stmt = conn.createStatement();
            try {
                String query = "select max(id) from term_candidat";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                resultSet.next();
                int idNumerique = resultSet.getInt(1);
                idTerm = "TC_" + (++idNumerique);

                /**
                 * Ajout des informations dans la table Concept
                 */
                query = "Insert into term_candidat " + "(id_term, lexical_value, lang, "
                        + "id_thesaurus, contributor)" + " values (" + "'" + idTerm + "'" + ",'" + lexical_value
                        + "'" + ",'" + idLang + "'" + ",'" + idThesaurus + "'" + "," + contributor + ")";

                stmt.executeUpdate(query);

            } finally {
                stmt.close();
            }
        } finally {
            //    conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while adding Term_candidat  : " + idTerm, sqle);
        idTerm = null;
    }
    return idTerm;
}

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

/**
 * Cette fonction permet de rcuprer les termes gnriques d'un concept
 *
 * @param ds/*w  w w.  j  a va  2s  . co  m*/
 * @param idConcept
 * @param idThesaurus
 * @param idLang
 * @return Objet class Concept
 */
public ArrayList<NodeBT> getListBT(HikariDataSource ds, String idConcept, String idThesaurus, String idLang) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeBT> nodeListBT = null;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT hierarchical_relationship.id_concept2,"
                        + " concept.status FROM hierarchical_relationship," + " concept WHERE "
                        + " concept.id_thesaurus = hierarchical_relationship.id_thesaurus" + " AND "
                        + " concept.id_concept = hierarchical_relationship.id_concept2" + " AND"
                        + " hierarchical_relationship.id_thesaurus = '" + idThesaurus + "'" + " AND"
                        + " hierarchical_relationship.id_concept1 = '" + idConcept + "'" + " AND"
                        + " hierarchical_relationship.role = 'BT'";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    nodeListBT = new ArrayList<>();
                    while (resultSet.next()) {
                        NodeBT nodeBT = new NodeBT();
                        nodeBT.setIdConcept(resultSet.getString("id_concept2"));
                        nodeBT.setStatus(resultSet.getString("status"));
                        nodeListBT.add(nodeBT);
                    }
                }
                for (NodeBT nodeBT : nodeListBT) {
                    query = "SELECT term.lexical_value, term.status FROM term, preferred_term"
                            + " WHERE preferred_term.id_term = term.id_term"
                            + " and preferred_term.id_concept ='" + nodeBT.getIdConcept() + "'"
                            + " and term.lang = '" + idLang + "'" + " and term.id_thesaurus = '" + idThesaurus
                            + "'" + " order by upper(unaccent_string(lexical_value)) DESC";

                    stmt.executeQuery(query);
                    resultSet = stmt.getResultSet();
                    if (resultSet != null) {
                        resultSet.next();
                        if (resultSet.getRow() == 0) {
                            nodeBT.setTitle("");
                            nodeBT.setStatus("");
                        } else {
                            if (resultSet.getString("lexical_value") == null
                                    || resultSet.getString("lexical_value").equals("")) {
                                nodeBT.setTitle("");
                            } else {
                                nodeBT.setTitle(resultSet.getString("lexical_value"));
                            }
                            if (resultSet.getString("status") == null
                                    || resultSet.getString("status").equals("")) {
                                nodeBT.setStatus("");
                            } else {
                                nodeBT.setStatus(resultSet.getString("status"));
                            }

                        }
                    }
                }

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

From source file:com.redhat.lightblue.rest.crud.ITCaseCrudResourceRDBMSTest.java

@Test
public void testInsert()
        throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException,
        InstantiationException, IllegalAccessException, URISyntaxException, JSONException {
    try {//from  ww w  . j  a va2s .  co 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.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("XXY",
                "INSERT INTO Country (NAME,ISO2CODE,ISO3CODE) VALUES (:name,:iso2code,:iso3code);");
        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 expectedInserted = readFile("expectedInserted.json");
        String resultInserted = cutCrudResource.insert("country", "1.0.0", readFile("resultInserted.json"))
                .getEntity().toString();
        System.err.println("!!!!!!!!!!!!!!!!!" + resultInserted);

        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("Canad", resultSet.getString("name"));
        Assert.assertEquals("CA", resultSet.getString("iso2code"));
        Assert.assertEquals("CAN", resultSet.getString("iso3code"));

        JSONAssert.assertEquals(expectedInserted, resultInserted, false);
    } catch (NamingException ex) {
        throw new IllegalStateException(ex);
    } catch (SQLException ex) {
        throw new IllegalStateException(ex);
    }
}

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

/**
 * Cette fonction permet de savoir si l'id du Candidat existe, si oui, on l'incrmente
 * @param conn/*from  w ww .  j  a  v  a  2  s .  com*/
 * @param idCandidat
 * @param idThesaurus
 * @return boolean
 */
public boolean isCandidatExist(Connection conn, String idCandidat, String idThesaurus) {

    Statement stmt;
    ResultSet resultSet;
    boolean existe = false;

    try {

        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept from concept_candidat where " + "id_concept = '" + idCandidat
                        + "'" + " 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 of Candidat exist : " + idCandidat, sqle);
    }
    return existe;
}

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

/**
 * Cette fonction permet de rajouter un term_candidat 
 * /*from   ww w  .j  a v  a  2s. c om*/
 * @param ds
 * @param lexical_value
 * @param idLang
 * @param idThesaurus
 * @param contributor
 * @return  idConceptCandidat
 */
public String addTermCandidat(HikariDataSource ds, String lexical_value, String idLang, String idThesaurus,
        int contributor) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    String idTerm = null;
    lexical_value = new StringPlus().convertString(lexical_value);
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select max(id) from term_candidat";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                resultSet.next();
                int idNumerique = resultSet.getInt(1);
                idTerm = "TC_" + (++idNumerique);

                /**
                 * Ajout des informations dans la table Concept
                 */
                query = "Insert into term_candidat " + "(id_term, lexical_value, lang, "
                        + "id_thesaurus, contributor)" + " values (" + "'" + idTerm + "'" + ",'" + lexical_value
                        + "'" + ",'" + idLang + "'" + ",'" + idThesaurus + "'" + "," + contributor + ")";

                stmt.executeUpdate(query);

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

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

/**
 * Cette fonction permet de rcuprer la liste des domaines pour
 * l'autocompltion/*from w  w w.j av a2  s  .  c o m*/
 *
 * @param ds
 * @param idThesaurus
 * @param text
 * @param idLang
 * @return Objet class Concept
 */
public List<NodeAutoCompletion> getAutoCompletionGroup(HikariDataSource ds, String idThesaurus, 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 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;
}