List of usage examples for java.sql Statement getResultSet
ResultSet getResultSet() throws SQLException;
ResultSet
object. 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 valid mais pas encore insrr dans les thsaurus (status = v) * 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 ww .java 2s . c o m*/ * @param idThesaurus * @param idLang * @return Objet Class ArrayList NodeCandidatValue */ public ArrayList<NodeCandidatValue> getListCandidatsValidated(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 = 'v' " + "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("v"); 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; }
From source file:mom.trd.opentheso.bdd.helper.CandidateHelper.java
/** * Cette fonction permet de savoir si le Candidat existe ou non * @param conn//ww w .j a v a 2 s.c o m * @param title * @param idThesaurus * @param idLang * @return boolean */ public boolean isCandidatExist_rollBack(Connection conn, String title, String idThesaurus, String idLang) { Statement stmt; ResultSet resultSet; boolean existe = false; StringPlus stringPlus = new StringPlus(); title = stringPlus.addQuotes(title); try { 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 != null) { resultSet.next(); if (resultSet.getRow() == 0) { existe = false; } else { existe = true; } } } 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.RelationsHelper.java
/** * Cette fonction permet de rcuprer la liste de l'historique des relations * d'un concept d'un concept//from www . j a v a 2s . c o m * * @param ds * @param idConcept * @param idThesaurus * @param lang * @return Objet class Concept */ public ArrayList<Relation> getRelationHistoriqueAll(HikariDataSource ds, String idConcept, String idThesaurus, String lang) { Connection conn; Statement stmt; ResultSet resultSet; ArrayList<Relation> listRel = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select lexical_value, id_concept2, role, action, hierarchical_relationship_historique.modified, username " + "from hierarchical_relationship_historique, users, preferred_term, term" + " where hierarchical_relationship_historique.id_thesaurus = '" + idThesaurus + "'" + " and hierarchical_relationship_historique.id_concept1=preferred_term.id_concept" + " and preferred_term.id_term=term.id_term" + " and term.lang='" + lang + "'" + " and term.id_thesaurus='" + idThesaurus + "'" + " and ( id_concept1 = '" + idConcept + "'" + " or id_concept2 = '" + idConcept + "' )" + " and hierarchical_relationship_historique.id_user=users.id_user" + " order by hierarchical_relationship_historique.modified DESC"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { listRel = new ArrayList<>(); while (resultSet.next()) { Relation r = new Relation(); r.setId_relation(resultSet.getString("role")); r.setId_concept1(resultSet.getString("lexical_value")); r.setId_concept2(resultSet.getString("id_concept2")); r.setModified(resultSet.getDate("modified")); r.setIdUser(resultSet.getString("username")); r.setAction(resultSet.getString("action")); r.setId_thesaurus(idThesaurus); listRel.add(r); } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting all relation historique of Concept : " + idConcept, sqle); } return listRel; }
From source file:org.apache.hive.jdbc.TestJdbcDriver2.java
@Test public void testShowRoleGrant() throws SQLException { Statement stmt = con.createStatement(); // drop role. ignore error. try {//from ww w . j a v a 2s. c o m stmt.execute("drop role role1"); } catch (Exception ex) { LOG.warn("Ignoring error during drop role: " + ex); } stmt.execute("create role role1"); stmt.execute("grant role role1 to user hive_test_user"); stmt.execute("show role grant user hive_test_user"); ResultSet res = stmt.getResultSet(); assertTrue(res.next()); assertEquals("public", res.getString(1)); assertTrue(res.next()); assertEquals("role1", res.getString(1)); res.close(); }
From source file:mom.trd.opentheso.bdd.helper.TermHelper.java
/** * Cette fonction permet de savoir si le terme existe ou non * * @param conn/*from w ww . java2 s.co m*/ * @param idTerm * @param idThesaurus * @return boolean */ public boolean isIdOfTermExist(Connection conn, String idTerm, String idThesaurus) { Statement stmt; ResultSet resultSet; boolean existe = false; try { try { stmt = conn.createStatement(); try { String query = "select id_term from term where " + " id_term = '" + idTerm + "'" + " 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 of Term exist : " + idTerm, 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 archivs * tous les status sauf a (a=attente, v=valid,i=insrr,r=refus) * 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/*w w w. j av a2 s . co m*/ * @param idThesaurus * @param idLang * @return Objet Class ArrayList NodeCandidatValue */ public ArrayList<NodeCandidatValue> getListCandidatsArchives(HikariDataSource ds, String idThesaurus, String idLang) { Connection conn; Statement stmt; ResultSet resultSet; ArrayList<NodeCandidatValue> nodeCandidatLists = null; ArrayList tabIdConcept = new ArrayList(); ArrayList tabStatus = new ArrayList(); NodeCandidatValue nodeCandidatValue = new NodeCandidatValue(); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select id_concept, status 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")); tabStatus.add(resultSet.getString("status")); } nodeCandidatLists = new ArrayList<>(); int i = 0; for (Object tabIdConcept1 : tabIdConcept) { nodeCandidatValue = getThisCandidat(ds, tabIdConcept1.toString(), idThesaurus, idLang); if (nodeCandidatValue == null) return null; nodeCandidatValue.setEtat(tabStatus.get(i++).toString()); 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; }
From source file:mom.trd.opentheso.bdd.helper.CandidateHelper.java
/** * Cette fonction permet de retourner le nombre de candidats d'un concept * * @param ds//from w w w. j a va 2s.c o m * @param idConcept * @param idThesaurus * @return Objet class NodeMessageAdmin */ public NodeMessageAdmin getMessageAdmin(HikariDataSource ds, String idThesaurus, String idConcept) { Connection conn; Statement stmt; ResultSet resultSet; NodeMessageAdmin nodeMessageAdmin = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT users.username, users.id_user," + " concept_candidat.admin_message" + " FROM concept_candidat, users WHERE" + " concept_candidat.admin_id = users.id_user" + " and concept_candidat.id_concept = '" + idConcept + "'" + " and concept_candidat.id_thesaurus = '" + idThesaurus + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet.next()) { nodeMessageAdmin = new NodeMessageAdmin(); nodeMessageAdmin.setId_user(resultSet.getInt("id_user")); nodeMessageAdmin.setUser(resultSet.getString("username")); nodeMessageAdmin.setMessage(resultSet.getString("admin_message")); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting Admin Message of candidat : " + idConcept, sqle); } return nodeMessageAdmin; }
From source file:migration.JournalMigration.java
/** * Run./*from w w w . jav a 2s.c o m*/ */ public void run() { // PORJEKTVERWALTUNG MIGRATION final ProjektMigration pmigration = new ProjektMigration(this.factory, this.help); System.out.println("[INFO] Erasing Database"); try { pmigration.cleanDB(); } catch (final SQLException e) { e.printStackTrace(); // To change body of catch statement use File | // Settings | File Templates. } try { System.out.println("[INFO] Establish Access-Database connection"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); final String filename = "d:/Access/EJFrontendTest.mdb"; // String database = // "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="; String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="; database += filename.trim() + ";DriverID=22;READONLY=true}"; final Connection con = DriverManager.getConnection(database, "", ""); System.out.println("[INFO] Connection successful"); /** * initialize variables for reuse */ String statement; Statement s; ResultSet rs; int laenge; /** * Anlegen von Arrays fr Tabellenbergnge */ /** * Tabelle Konsortium */ System.out.println("[INFO] Processing Konsortium"); statement = "select Konsortium from Konsortien ORDER BY Konsortium ASC"; final String[] stringKonsortien = this.help.sqlToStringArray(con, statement, 1); if (this.verbose || false) { this.help.printArray(stringKonsortien); } final Konsortium[] konsortien = this.help.createKonsortiumArray(stringKonsortien); if (this.verbose || false) { this.help.printObjectArray(konsortien, "Konsortium"); } this.writeToDB(konsortien, "Konsortium"); /** * Tabelle Paket */ statement = "select Paketbez from Pakettabelle ORDER BY Paketbez ASC"; System.out.println("[INFO] Processing Paket"); final String[] stringPakets = this.help.sqlToStringArray(con, statement, 1); if (this.verbose || false) { this.help.printArray(stringPakets); } final Paket[] pakets = this.help.createPaketArray(stringPakets); if (this.verbose || false) { this.help.printObjectArray(pakets, "Paket"); } this.writeToDB(pakets, "Paket"); /** * Umziehen der Tabellen */ /** * Tabelle Bibliotheksmitarbeiter - keine Abhngigkeiten => Group 01 */ s = con.createStatement(); statement = "select ID, Bibliotheksname AS xName, AbteilungoderHauptstelle AS AbteilungHauptstelle, FensterumschlagAdresse, " + "Hausanschrift, Postfachanschrift AS Postanschrift, Telefon, Telefax, Emailanschrift, HomepageImInternet AS URL, " + "UmsatzsteuerNummer AS UmstID, Mitarbeiter, Dienstort from Bibliothekstabelle ORDER BY ID ASC"; laenge = this.help.sqlGetLength(con, statement); s.execute(statement); rs = s.getResultSet(); Bibliotheksmitarbeiter[] mitarbeiter = new Bibliotheksmitarbeiter[0]; if (rs != null) { System.out.println("[INFO] Processing Bibliotheksmitarbeiter"); mitarbeiter = this.help.createMitarbeiterArray(rs, laenge); if (this.verbose || false) { this.help.printObjectArray(mitarbeiter, "Bibliotheksmitarbeiter"); } this.writeToDB(mitarbeiter, "Bibliotheksmitarbeiter"); } /** * Tabelle Institution - abhngig von Bibliotheksmitarbeiter => * Group 01 */ s = con.createStatement(); statement = "select Verlag AS xName, Abteilung, Strasse, Postfach, PLZOrt, Bundesland, Land, " + "Ansprechpartner, Email, Fax, Telefon, Bestellsprache, Bestellart, Status, Kennwoerter, " + "Fernzugriff, FernzugangErl, Zugang, Personengruppe, Zugangsdaten, Kommentar, KommentarIntern, " + "Internetadresse, NutzungURL, CopyrightURL, AccountURL, StatistikURL, SFXURL, UBlogoURL, " + "StatistikZugang, Fernleihe, LizenzArt, LizenzAbbest, LizenzPaket, LizenzVorg, LizenzZust, " + "LizenzBes, ID from Verlagstabelle"; laenge = this.help.sqlGetLength(con, statement); s.execute(statement); rs = s.getResultSet(); Institution[] institutions = new Institution[0]; if (rs != null) { System.out.println("[INFO] Processing Institution"); institutions = this.help.createInstitutionArray(rs, laenge, this.factory); if (this.verbose || false) { this.help.printObjectArray(institutions, "Institution"); } this.writeToDB(institutions, "Institution"); } /** * Tabelle Lizenzdetail - Abhngig von Institution => Group 02 */ s = con.createStatement(); statement = "select LizenzID AS id, Verlag, Beginn, Laufzeit, Verlaengerung, Kosten, " + "Readmeakt AS ReadmeAktualisiert from LizenzdetailTabelle"; laenge = this.help.sqlGetLength(con, statement); s.execute(statement); rs = s.getResultSet(); Lizenzdetail[] lizenzdetails = new Lizenzdetail[0]; if (rs != null) { System.out.println("[INFO] Processing Lizenzdetails"); lizenzdetails = this.help.createLizenzdetailArray(rs, laenge, institutions, this.factory); if (this.verbose || false) { this.help.printObjectArray(lizenzdetails, "Lizenzdetail"); } this.writeToDB(lizenzdetails, "Lizenzdetail"); } /** * reading Fach */ s = con.createStatement(); statement = "select Fach AS ID, FachText AS xName from Faechertabelle"; laenge = this.help.sqlGetLength(con, statement); s.execute(statement); rs = s.getResultSet(); Fach[] faecher = new Fach[0]; if (rs != null) { System.out.println("[INFO] Processing Fach"); faecher = this.help.createFachArray(rs, laenge); if (this.verbose || false) { this.help.printObjectArray(faecher, "Fach"); } this.writeToDB(faecher, "Fach"); } /** * reading Journal */ s = con.createStatement(); statement = "select Titelnummer AS ID, Verlag, Provider, Konsortium, Paketbez AS Paket, Bibliotheksnummer AS Bibliothek, Titel, Kurztitel, " + "ISSN, ISSNPrint, KommentarProjekte AS Kommentar, Kommentar AS KommentarAdmin, KommentarFrei AS KommentarIntranet, Anmeldedatum, Freischaltdatum, " + "ZugangsID, ZugangsPasswort, Nutzungsbestimmungen, Rotschaltungsdatum, Rotschaltungsbemerkungen, " + "Status, Aenderungsdatum, ZDBNummer, EZBID, Anker, Readmetitelbezogen, Herausgeber, ZugangUeber, Fach1, Fach2, Fach3, Termin from ZSTiteltabelle"; laenge = this.help.sqlGetLength(con, statement); s.execute(statement); rs = s.getResultSet(); Journal[] journals = new Journal[0]; if (rs != null) { System.out.println("[INFO] Processing Journals"); /* * while (rs.next()){ help.printTableRow(rs, false, 50); } */ journals = this.help.createJournalArray(rs, laenge, this.factory, stringPakets, stringKonsortien); if (this.verbose || false) { this.help.printObjectArray(journals, "Journal"); } this.writeToDB(journals, "Journal"); } /** * reading Sigel */ s = con.createStatement(); statement = "select Sigel, Bereichsname AS Bibliothek, Fakultaet, PersEmail, Bibansprechpartner1, " + "Bibansprechpartner2 from Sigeltabelle"; laenge = this.help.sqlGetLength(con, statement); s.execute(statement); rs = s.getResultSet(); Sigel[] sigels = new Sigel[0]; if (rs != null) { System.out.println("[INFO] Processing Sigel"); sigels = this.help.createSigelArray(rs, laenge, this.factory); if (this.verbose || false) { this.help.printObjectArray(sigels, "Sigel"); } this.writeToDB(sigels, "Sigel"); } /** * connect Journal_Fach */ System.out.println("[INFO] Connecting Journal_Fach"); pmigration.connectJournalFach(); /** * reading Besteller */ System.out.println("[INFO] Processing Besteller"); pmigration.createBesteller(con); /** * reading Exemplar */ System.out.println("[INFO] Processing Exemplar"); pmigration.createExemplar(con); /** * reading Nutzung */ System.out.println("[INFO] Processing Nutzung"); pmigration.createNutzung(); /** * reading Journalkosten */ System.out.println("[INFO] Processing Journalkosten"); pmigration.createJournalkosten(); /** * reading Rechnung */ System.out.println("[INFO] Processing Rechnung"); pmigration.createRechnung(); /** * reading Interessen */ System.out.println("[INFO] Processing Interessen"); pmigration.createInteressen(); System.out.println("[INFO] DONE"); s.close(); // close the Statement to let the database know we're // done with it con.close(); // close the Connection to let the database know we're // done with it } catch (final Exception e) { System.out.println("FUCK --- Error: " + e); e.printStackTrace(); } }
From source file:mom.trd.opentheso.bdd.helper.RelationsHelper.java
/** * Cette fonction permet de rcuprer la liste de l'historique des relations * d'un concept une date prcise d'un concept * * @param ds/*from w w w . j a v a2 s . c o m*/ * @param idConcept * @param idThesaurus * @param date * @param lang * @return Objet class Concept */ public ArrayList<Relation> getRelationHistoriqueFromDate(HikariDataSource ds, String idConcept, String idThesaurus, Date date, String lang) { Connection conn; Statement stmt; ResultSet resultSet; ArrayList<Relation> listRel = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select lexical_value, id_concept2, role, action, hierarchical_relationship_historique.modified, username " + "from hierarchical_relationship_historique, users, preferred_term, term" + " where hierarchical_relationship_historique.id_thesaurus = '" + idThesaurus + "'" + " and hierarchical_relationship_historique.id_concept1=preferred_term.id_concept" + " and preferred_term.id_term=term.id_term" + " and term.lang='" + lang + "'" + " and term.id_thesaurus='" + idThesaurus + "'" + " and ( id_concept1 = '" + idConcept + "'" + " or id_concept2 = '" + idConcept + "' )" + " and hierarchical_relationship_historique.id_user=users.id_user" + " and hierarchical_relationship_historique.modified <= '" + date.toString() + "' order by hierarchical_relationship_historique.modified ASC"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { listRel = new ArrayList<>(); while (resultSet.next()) { if (resultSet.getString("action").equals("DEL")) { for (Relation rel : listRel) { if (rel.getId_concept1().equals(resultSet.getString("lexical_value")) && rel.getId_concept2().equals(resultSet.getString("id_concept2")) && rel.getAction().equals("ADD") && rel.getId_relation().equals(resultSet.getString("role"))) { listRel.remove(rel); break; } } } else { Relation r = new Relation(); r.setId_relation(resultSet.getString("role")); r.setId_concept1(resultSet.getString("lexical_value")); r.setId_concept2(resultSet.getString("id_concept2")); r.setModified(resultSet.getDate("modified")); r.setIdUser(resultSet.getString("username")); r.setAction(resultSet.getString("action")); r.setId_thesaurus(idThesaurus); listRel.add(r); } } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting date relation historique of Concept : " + idConcept, sqle); } return listRel; }
From source file:mom.trd.opentheso.bdd.helper.TermHelper.java
/** * * @param conn//from ww w . j a va2 s . c om * @param term * @param idUser * @return idTerm */ public String addNewTerm(Connection conn, Term term, int idUser) { String idTerm = null; // Connection conn; Statement stmt; ResultSet resultSet; term.setLexical_value(new StringPlus().convertString(term.getLexical_value())); try { // Get connection from pool // conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select max(id) from term"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); resultSet.next(); int idTermNum = resultSet.getInt(1); idTermNum++; idTerm = "" + (idTermNum); // si le nouveau Id existe, on l'incrmente while (isIdOfTermExist(conn, idTerm, term.getId_thesaurus())) { idTerm = "" + (++idTermNum); } term.setId_term(idTerm); /** * Ajout des informations dans la table Concept */ query = "Insert into term " + "(id_term, lexical_value, lang, " + "id_thesaurus, source, status, contributor, creator)" + " values (" + "'" + term.getId_term() + "'" + ",'" + term.getLexical_value() + "'" + ",'" + term.getLang() + "'" + ",'" + term.getId_thesaurus() + "'" + ",'" + term.getSource() + "'" + ",'" + term.getStatus() + "'" + ", " + idUser + "" + ", " + idUser + ")"; stmt.executeUpdate(query); addNewTermHistorique(conn, term, idUser); } finally { stmt.close(); } } finally { // conn.close(); } } catch (SQLException sqle) { // Log exception if (!sqle.getSQLState().equalsIgnoreCase("23505")) idTerm = null; } return idTerm; }