List of usage examples for java.sql Statement getResultSet
ResultSet getResultSet() throws SQLException;
ResultSet
object. From source file:mom.trd.opentheso.bdd.helper.GroupHelper.java
/** * Permet de retourner le lexical Value of Group * * @param ds le pool de connexion/*from ww w.j a va2s . com*/ * @param idConceptGroup * @param idThesaurus * @param idLang * @return Objet Class NodeConceptGroup */ public String getLexicalValueOfGroup(HikariDataSource ds, String idConceptGroup, String idThesaurus, String idLang) { Connection conn; Statement stmt; ResultSet resultSet; String lexicalValue = ""; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT lexicalvalue FROM concept_group_label" + " WHERE idthesaurus = '" + idThesaurus + "'" + " and idgroup = '" + idConceptGroup + "'" + " and lang = '" + idLang + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet.next()) { lexicalValue = resultSet.getString("lexicalvalue"); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting lexical value of Group : " + idConceptGroup, sqle); } return lexicalValue; }
From source file:mom.trd.opentheso.bdd.helper.GroupHelper.java
/** * Permet de retourner un NodeConceptGroup par identifiant, par thsaurus et * par langue / ou null si rien cette fonction ne retourne pas les dtails * et les traductions// w w w . j av a 2 s . c o m * * @param ds le pool de connexion * @param idConceptGroup * @param idThesaurus * @param idLang * @return Objet Class NodeConceptGroup */ public NodeGroup getThisConceptGroup(HikariDataSource ds, String idConceptGroup, String idThesaurus, String idLang) { Connection conn; Statement stmt; ResultSet resultSet; NodeGroup nodeConceptGroup = null; ConceptGroup conceptGroup = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT * from concept_group where " + " idgroup = '" + idConceptGroup + "'" + " and idthesaurus = '" + idThesaurus + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { resultSet.next(); if (resultSet.getRow() != 0) { conceptGroup = new ConceptGroup(); conceptGroup.setIdgroup(idConceptGroup); conceptGroup.setIdthesaurus(idThesaurus); conceptGroup.setIdARk(resultSet.getString("id_ark")); conceptGroup.setIdtypecode(resultSet.getString("idtypecode")); conceptGroup.setNotation(resultSet.getString("notation")); } } if (conceptGroup != null) { query = "SELECT * FROM concept_group_label WHERE" + " idgroup = '" + conceptGroup.getIdgroup() + "'" + " AND idthesaurus = '" + idThesaurus + "'" + " AND lang = '" + idLang + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { nodeConceptGroup = new NodeGroup(); resultSet.next(); if (resultSet.getRow() == 0) { // cas du Group non traduit nodeConceptGroup.setLexicalValue(""); nodeConceptGroup.setIdLang(idLang); } else { nodeConceptGroup.setLexicalValue(resultSet.getString("lexicalvalue")); nodeConceptGroup.setIdLang(idLang); nodeConceptGroup.setCreated(resultSet.getDate("created")); nodeConceptGroup.setModified(resultSet.getDate("modified")); } nodeConceptGroup.setConceptGroup(conceptGroup); } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while adding element : " + idThesaurus, sqle); } return nodeConceptGroup; }
From source file:mom.trd.opentheso.bdd.helper.RelationsHelper.java
/** * Cette fonction permet de rcuprer les termes associs d'un concept * * @param ds// www . j av a 2 s . c om * @param idConcept * @param idThesaurus * @param idLang * @return Objet class Concept */ public ArrayList<NodeRT> getListRT(HikariDataSource ds, String idConcept, String idThesaurus, String idLang) { Connection conn; Statement stmt; ResultSet resultSet; ArrayList<NodeRT> nodeListRT = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select id_concept2, status from hierarchical_relationship, concept" + " where hierarchical_relationship.id_thesaurus = '" + idThesaurus + "'" + " and hierarchical_relationship.id_concept2 = concept.id_concept" + " and id_concept1 = '" + idConcept + "'" + " and role = '" + "RT" + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { nodeListRT = new ArrayList<>(); while (resultSet.next()) { NodeRT nodeRT = new NodeRT(); nodeRT.setIdConcept(resultSet.getString("id_concept2")); nodeRT.setStatus(resultSet.getString("status")); nodeListRT.add(nodeRT); } } for (NodeRT nodeRT : nodeListRT) { query = "SELECT term.lexical_value FROM" + " term, preferred_term WHERE" + " term.id_term = preferred_term.id_term" + " and preferred_term.id_concept = '" + nodeRT.getIdConcept() + "'" + " and term.lang = '" + idLang + "'" + " and term.id_thesaurus = '" + idThesaurus + "'" + " order by upper(unaccent_string(term.lexical_value))"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { resultSet.next(); if (resultSet.getRow() == 0) { nodeRT.setTitle(""); } else { nodeRT.setTitle(resultSet.getString("lexical_value")); } } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting RT of Concept : " + idConcept, sqle); } return nodeListRT; }
From source file:org.talend.metadata.managment.model.DBConnectionFillerImpl.java
/** * DOC scorreia Comment method "executeGetCommentStatement". * /* ww w . j av a 2s . com*/ * @param queryStmt * @return */ private String executeGetCommentStatement(String queryStmt, java.sql.Connection connection) { String comment = null; Statement statement = null; ResultSet resultSet = null; try { statement = connection.createStatement(); statement.execute(queryStmt); // get the results resultSet = statement.getResultSet(); if (resultSet != null) { while (resultSet.next()) { comment = (String) resultSet.getObject(1); } } } catch (SQLException e) { // do nothing here } finally { // -- release resources if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { log.error(e, e); } } if (statement != null) { try { statement.close(); } catch (SQLException e) { log.error(e, e); } } } return comment; }
From source file:mom.trd.opentheso.bdd.helper.GroupHelper.java
/** * Cette fonction permet de savoir si le Domaine existe dans cette langue * * @param ds/*from ww w . ja v a 2s. com*/ * @param title * @param idThesaurus * @param idLang * @return boolean */ public boolean isDomainExist(HikariDataSource ds, String title, String idThesaurus, String idLang) { Connection conn; Statement stmt; ResultSet resultSet; boolean existe = false; title = new StringPlus().convertString(title); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select idgroup from concept_group_label where " + "unaccent_string(lexicalvalue) ilike " + "unaccent_string('" + title + "') and lang = '" + idLang + "' and idthesaurus = '" + 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 Term exist : " + title, sqle); } return existe; }
From source file:org.talend.dq.analysis.ColumnAnalysisSqlExecutor.java
/** * /*w w w.jav a 2s . com*/ * @param catalogName (can be null) * @param connection * @param queryStmt * @return * @throws SQLException */ protected List<Object[]> executeQuery(String catalogName, Connection connection, String queryStmt) throws SQLException { // set current thread classLoader if it is hive connection ClassLoader currClassLoader = Thread.currentThread().getContextClassLoader(); org.talend.core.model.metadata.builder.connection.Connection dbConn = this .getAnalysisDataProvider(cachedAnalysis); IMetadataConnection metadataBean = ConvertionHelper.convert(dbConn); if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataBean.getDbType())) { ClassLoader hiveClassLoader = HiveClassLoaderFactory.getInstance().getClassLoader(metadataBean); Thread.currentThread().setContextClassLoader(hiveClassLoader); } List<Object[]> myResultSet = new ArrayList<Object[]>(); Statement statement = null; try { if (catalogName != null && needChangeCatalog(connection)) { // check whether null argument can be given changeCatalog(catalogName, connection); } // MOD xqliu 2009-02-09 bug 6237 if (continueRun()) { // create query statement statement = connection.createStatement(); // statement.setFetchSize(fetchSize); statement.execute(queryStmt); // get the results ResultSet resultSet = statement.getResultSet(); if (resultSet == null) { String mess = Messages.getString("ColumnAnalysisSqlExecutor.NORESULTSETFORTHISSTATEMENT") //$NON-NLS-1$ + queryStmt; log.warn(mess); return null; } ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); while (resultSet.next()) { Object[] result = new Object[columnCount]; for (int i = 0; i < columnCount; i++) { result[i] = ResultSetUtils.getBigObject(resultSet, i + 1); } myResultSet.add(result); } resultSet.close(); } // -- release resources } catch (NullPointerException nullExc) { // TDQ-11851 when click 'cancel' on wizard,the connection should be closed, so that some object may be Null.Catch the // Exception and logging here. if (getMonitor() != null && getMonitor().isCanceled()) { log.error(nullExc); } else { throw nullExc; } } finally { if (statement != null) { statement.close(); } Thread.currentThread().setContextClassLoader(currClassLoader); } return myResultSet; }
From source file:com.cisco.dvbu.ps.deploytool.services.RegressionManagerUtils.java
/** * Similar to the same method in original pubtest utility, but doesn't throw an exception if 0 rows are returned * and uses existing(established) JDBC connection corresponding to its published datasource name. * /*w w w .j ava 2s .c om*/ * @param item * * @return result - A string containing a formatted response with the rows and first row latency: <rows>:<firstRowLatency> */ public static String executeQuery(RegressionItem item, HashMap<String, Connection> cisConnections, String outputFile, String delimiter, String printOutputType) throws CompositeException { // Set the command and action name String command = "executeQuery"; String actionName = "REGRESSION_TEST"; int rows = 0; String result = null; Connection conn = null; Statement stmt = null; ResultSet rs = null; start = System.currentTimeMillis(); long firstRowLatency = 0L; // Don't execute if -noop (NO_OPERATION) has been set otherwise execute under normal operation. if (CommonUtils.isExecOperation()) { try { conn = getJdbcConnection(item.database, cisConnections); // don't need to check for null here. String URL = null; String userName = null; if (conn.getMetaData() != null) { if (conn.getMetaData().getURL() != null) URL = conn.getMetaData().getURL(); if (conn.getMetaData().getUserName() != null) userName = conn.getMetaData().getUserName(); } RegressionManagerUtils.printOutputStr(printOutputType, "debug", "RegressionManagerUtils.executeQuery(item, cisConnections, outputFile, delimiter, printOutputType). item.database=" + item.database + " cisConnections.URL=" + URL + " cisConnections.userName=" + userName + " outputFile=" + outputFile + " delimiter=" + delimiter + " printOutputType=" + printOutputType, ""); RegressionManagerUtils.printOutputStr(printOutputType, "debug", "DEBUG: connection to DB successful", ""); stmt = conn.createStatement(); stmt.execute(item.input.replaceAll("\n", " ")); rs = stmt.getResultSet(); ResultSetMetaData rsmd = rs.getMetaData(); int columns = rsmd.getColumnCount(); RegressionManagerUtils.printOutputStr(printOutputType, "debug", "DEBUG: number metadata columns=" + columns, ""); // Get the column metadata boolean addSep = false; String content = ""; RegressionManagerUtils.printOutputStr(printOutputType, "debug", "DEBUG: Get column metadata.", ""); for (int i = 0; i < columns; i++) { if (addSep) { content += delimiter; } if (rsmd.getColumnName(i + 1) != null) content += rsmd.getColumnName(i + 1).toString(); else content += ""; addSep = true; } if (outputFile != null) CommonUtils.appendContentToFile(outputFile, content); RegressionManagerUtils.printOutputStr(printOutputType, "results", content, ""); // Read the values boolean firstRow = true; RegressionManagerUtils.printOutputStr(printOutputType, "debug", "DEBUG: Begin Query Loop.", ""); while (rs.next()) { if (firstRow) { firstRowLatency = System.currentTimeMillis() - start; firstRow = false; RegressionManagerUtils.printOutputStr(printOutputType, "debug", "DEBUG: Set first row latency time=" + firstRowLatency, ""); } addSep = false; content = ""; for (int i = 0; i < columns; i++) { if (addSep) { content += delimiter; } if (rs.getObject(i + 1) != null) content += rs.getObject(i + 1).toString(); else content += ""; addSep = true; } if (outputFile != null) CommonUtils.appendContentToFile(outputFile, content); RegressionManagerUtils.printOutputStr(printOutputType, "results", content, ""); rows++; } } catch (SQLException e) { RegressionManagerUtils.printOutputStr(printOutputType, "debug", "DEBUG: Exception caught in RegressionManagerUtils.executeQuery:", ""); RegressionManagerUtils.printOutputStr(printOutputType, "debug", e.getMessage(), ""); throw new CompositeException("executeQuery(): " + e.getMessage()); } finally { try { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } } catch (SQLException e) { rs = null; stmt = null; throw new CompositeException( "executeQuery(): unable to close ResultSet or Statement" + e.getMessage()); } } RegressionManagerUtils.printOutputStr(printOutputType, "results", "\nCompleted executeQuery()", ""); } else { logger.info("\n\nWARNING - NO_OPERATION: COMMAND [" + command + "], ACTION [" + actionName + "] WAS NOT PERFORMED.\n"); } // <rows>:<firstRowLatency> result = "" + rows + ":" + firstRowLatency; return result; /* Note: to process this result string on the client invocation side use the following pattern: * * String result = RegressionManagerUtils.executeQuery(item, cisConnections, outputFile, delim, printOutputType, "results"); String results[] = result.split(":"); if (results.length > 1) { rowCount = Integer.valueOf(results[0]); firstRowLatency.addAndGet(Long.parseLong(results[1])); } */ }
From source file:mom.trd.opentheso.bdd.helper.GroupHelper.java
/** * Cette fonction permet d'ajouter un group (MT, domaine etc..) avec le * libell//w w w .j a v a2 s .c o m * * @param ds * @param nodeConceptGroup * @param urlSite * @param isArkActive * @param idUser * @return */ public String addGroup(HikariDataSource ds, NodeGroup nodeConceptGroup, String urlSite, boolean isArkActive, int idUser) { String idConceptGroup = "";//"ark:/66666/srvq9a5Ll41sk"; Connection conn; Statement stmt; ResultSet resultSet; nodeConceptGroup.setLexicalValue(new StringPlus().convertString(nodeConceptGroup.getLexicalValue())); /* * rcupration de l'identifiant Ark pour le ConceptGroup * de type : ark:/66666/srvq9a5Ll41sk */ /** * Controler si l'identifiant du Group existe */ // faire try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select max(id) from concept_group"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); resultSet.next(); int idNumeriqueGroup = resultSet.getInt(1); idConceptGroup = "MT_" + (++idNumeriqueGroup); /** * rcupration du code Ark via WebServices * */ String idArk = ""; if (isArkActive) { ArrayList<DcElement> dcElementsList = new ArrayList<>(); Ark_Client ark_Client = new Ark_Client(); idArk = ark_Client.getArkId(new FileUtilities().getDate(), urlSite + "?idg=" + idConceptGroup + "&idt=" + nodeConceptGroup.getConceptGroup().getIdthesaurus(), "", "", dcElementsList, "pcrt"); // pcrt : p= pactols, crt=code DCMI pour collection } /** * Ajout des informations dans la table de ConceptGroup */ query = "Insert into concept_group values (" + "'" + idConceptGroup + "'" + ",'" + idArk + "'" + ",'" + nodeConceptGroup.getConceptGroup().getIdthesaurus() + "'" + ",'" + nodeConceptGroup.getConceptGroup().getIdtypecode() + "'" + ",'" + nodeConceptGroup.getConceptGroup().getNotation() + "'" + ")"; stmt.executeUpdate(query); ConceptGroupLabel conceptGroupLabel = new ConceptGroupLabel(); conceptGroupLabel.setIdgroup(idConceptGroup); conceptGroupLabel.setIdthesaurus(nodeConceptGroup.getConceptGroup().getIdthesaurus()); conceptGroupLabel.setLang(nodeConceptGroup.getIdLang()); conceptGroupLabel.setLexicalvalue(nodeConceptGroup.getLexicalValue()); addGroupTraduction(ds, conceptGroupLabel, idUser); addGroupHistorique(ds, nodeConceptGroup, urlSite, idArk, idUser, idConceptGroup); } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while adding ConceptGroup : " + idConceptGroup, sqle); } return idConceptGroup; }
From source file:migration.ProjektMigration.java
/** * Creates the exemplar./*from www .j a v a 2 s . c o m*/ * * @param con * the con */ public void createExemplar(final Connection con) { String load_sql; Statement load_stmt; ResultSet load_rs; String store_sql; PreparedStatement store_prepstmt; final ResultSet store_rs; try { load_sql = "select Besteller, Exemplar, Sigel, Titelnummer AS Journal, Lieferant, Printan, Beteiligung, Form, Zugangsart, " + "Status, Bestellnummer, Kundennummer, AboNummer, Privatabo, ExKommentar, PrintexBayern, " + "AbbestZum, Abbestellung, UmbestZum, Umbestellung from Exemplartabelle "; load_stmt = this.leg_con.createStatement(); store_sql = "insert into exemplar (abbestZum, abbestellung, abonummer, bestellnummer, beteiligung, " + "exKommentar, form, kundennummer, printexBayern, privatabo, status, umbestZum, umbestellung, zugangsart, " + "besteller_sigelId, eigentuemer_sigelId, journal_id, lieferant_id, zustaendigeBib_sigelId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; store_prepstmt = this.tgt_con.prepareStatement(store_sql); // evtl. // brauchen // wir // was // in // Richtung: // Statement.RETURN_GENERATED_KEYS final int laenge = this.help.sqlGetLength(con, load_sql); this.exemplare = new int[laenge]; // logger.info("Lese von Besteller"); load_stmt.execute(load_sql); load_rs = load_stmt.getResultSet(); // logger.info("Schreibe nach Besteller"); for (int i = 0; i < laenge; i++) { // System.err.println("geht doch!"); load_rs.next(); this.exemplare[i] = load_rs.getInt("Exemplar"); store_prepstmt.setDate(1, load_rs.getDate("AbbestZum")); store_prepstmt.setString(2, load_rs.getString("Abbestellung")); store_prepstmt.setString(3, load_rs.getString("AboNummer")); store_prepstmt.setString(4, load_rs.getString("Bestellnummer")); store_prepstmt.setString(5, load_rs.getString("Beteiligung")); store_prepstmt.setString(6, load_rs.getString("exKommentar")); store_prepstmt.setString(7, load_rs.getString("Form")); store_prepstmt.setString(8, load_rs.getString("Kundennummer")); store_prepstmt.setString(9, load_rs.getString("PrintexBayern")); store_prepstmt.setBoolean(10, load_rs.getBoolean("privatabo")); store_prepstmt.setString(11, load_rs.getString("Status")); store_prepstmt.setDate(12, load_rs.getDate("UmbestZum")); store_prepstmt.setString(13, load_rs.getString("Umbestellung")); store_prepstmt.setString(14, load_rs.getString("Zugangsart")); final String besteller = load_rs.getString("Besteller"); final int bestellerID_neu = this.help.getIdFromStringArray(this.bestellers, besteller); int sigelID = 0; if (bestellerID_neu != 0) { sigelID = this.bestellers_sigels[bestellerID_neu - 1]; } if (sigelID != 0) { store_prepstmt.setLong(15, sigelID); } else { store_prepstmt.setNull(15, java.sql.Types.BIGINT); } final String print = load_rs.getString("Printan"); // System.err.println("print: "+print+" getID: "+help.getIdFromStringArray(help.getSigel(), // print)); if (this.help.getIdFromStringArray(this.help.getSigel(), print) != 0) { store_prepstmt.setLong(16, (this.help.getIdFromStringArray(this.help.getSigel(), print))); } else { store_prepstmt.setNull(16, java.sql.Types.BIGINT); } final int j = load_rs.getInt("Journal"); // System.err.println("journal: "+j+" getID: "+help.getIdFromIntArray(help.getJournals(), // j)); if (this.help.getIdFromIntArray(this.help.getJournals(), j) != 0) { store_prepstmt.setLong(17, this.help.getIdFromIntArray(this.help.getJournals(), j)); } else { store_prepstmt.setNull(17, java.sql.Types.BIGINT); } final String lief = load_rs.getString("Lieferant"); // System.err.println("lieferant: "+ lief + // " ist "+help.getIdFromStringArray(help.getInstitutionen(), // lief)); if (this.help.getIdFromStringArray(this.help.getInstitutionen(), lief) != 0) { store_prepstmt.setLong(18, this.help.getIdFromStringArray(this.help.getInstitutionen(), lief)); } else { store_prepstmt.setNull(18, java.sql.Types.BIGINT); } final String s = load_rs.getString("Sigel"); // System.err.println("zustndige Bib: "+ s + // " ist "+help.getIdFromStringArray(help.getSigel(), s)); if (this.help.getIdFromStringArray(this.help.getSigel(), s) != 0) { store_prepstmt.setLong(19, this.help.getIdFromStringArray(this.help.getSigel(), s)); } else { store_prepstmt.setNull(19, java.sql.Types.BIGINT); } store_prepstmt.executeUpdate(); } } catch (final SQLException e) { e.printStackTrace(); // To change body of catch statement use File | // Settings | File Templates. } // insert into Interesse (besteller_bestellerId, interesse, journal_id) // values (?, ?, ?) // insert into Nutzung (journal_id, nutzungsjahr, rechnungsbetrag, // zeitraum, zugriffe) values (?, ?, ?, ?, ?) // insert into Rechnung (betrag, bezugsform, bezugsjahr, // exemplar_exemplarId, sigel_sigelId) values (?, ?, ?, ?, ?) }
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/* w ww. ja va2s . c o m*/ * * @param conn * @param idThesaurus * @return idConceptCandidat */ public String addConceptCandidat_rollback(Connection conn, String idThesaurus) { String idConcept = null; Statement stmt; ResultSet resultSet; try { 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(conn, 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); idConcept = null; } return idConcept; }