List of usage examples for java.sql Statement getResultSet
ResultSet getResultSet() throws SQLException;
ResultSet
object. From source file:mom.trd.opentheso.bdd.helper.NoteHelper.java
/** * pour pouvoir obtener une list des Notes a partir du idConcept * sans conter avec le language//from w w w.j a v a 2 s .c om * @param ds * @param idConcept * @param idThesaurus * @return */ public ArrayList<NodeNote> getListNotesConcept2(HikariDataSource ds, String idConcept, String idThesaurus) { ArrayList<NodeNote> nodeNotes = new ArrayList<>(); Connection conn; Statement stmt; ResultSet resultSet; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT note.id, note.lang, note.notetypecode," + " note.lexicalvalue, note.created," + " note.modified FROM note, note_type" + " WHERE note.notetypecode = note_type.code" + " and note_type.isconcept = true" + " and note.id_concept = '" + idConcept + "'" + " and note.id_thesaurus = '" + idThesaurus + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); while (resultSet.next()) { NodeNote nodeNote = new NodeNote(); nodeNote.setId_concept(idConcept); nodeNote.setId_note(resultSet.getInt("id")); nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue")); nodeNote.setModified(resultSet.getDate("modified")); nodeNote.setCreated(resultSet.getDate("created")); nodeNote.setNotetypecode(resultSet.getString("notetypecode")); nodeNote.setLang(resultSet.getString("lang")); nodeNotes.add(nodeNote); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting Notes of Concept : " + idConcept, sqle); } return nodeNotes; }
From source file:mom.trd.opentheso.bdd.helper.NoteHelper.java
/** * Cette focntion permet de retourner la liste des notes pour un Term(type * HistoryNote, Definition, EditotrialNote) dans toutes les langues * * @param ds//from www. ja v a 2 s . c o m * @param idThesaurus * @param idTerm * @return ArrayList des notes sous forme de Class NodeNote */ public ArrayList<NodeNote> getListNotesTermAllLang(HikariDataSource ds, String idTerm, String idThesaurus) { ArrayList<NodeNote> nodeNotes = new ArrayList<>(); Connection conn; Statement stmt; ResultSet resultSet; StringPlus stringPlus = new StringPlus(); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT note.id, note.notetypecode," + " note.lexicalvalue, note.created," + " note.modified, note.lang FROM note, note_type" + " WHERE note.notetypecode = note_type.code" + " and note_type.isterm = true" + " and note.id_term = '" + idTerm + "'" + " and note.id_thesaurus = '" + idThesaurus + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); while (resultSet.next()) { NodeNote nodeNote = new NodeNote(); nodeNote.setId_term(idTerm); nodeNote.setId_note(resultSet.getInt("id")); nodeNote.setLang(resultSet.getString("lang")); nodeNote.setLexicalvalue( stringPlus.normalizeStringForXml(resultSet.getString("lexicalvalue"))); nodeNote.setModified(resultSet.getDate("modified")); nodeNote.setCreated(resultSet.getDate("created")); nodeNote.setNotetypecode(resultSet.getString("notetypecode")); nodeNotes.add(nodeNote); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting All Notes of Term : " + idTerm, sqle); } return nodeNotes; }
From source file:mom.trd.opentheso.bdd.helper.ThesaurusHelper.java
/** * Permet de crer un nouveau Thsaurus. Retourne l'identifiant du thsaurus * ou null// www .j av a2 s . co m * * @param conn * @param thesaurus * @param urlSite * @param isArkActive * @return String Id du thsaurus rajout */ public String addThesaurusRollBack(Connection conn, Thesaurus thesaurus, String urlSite, boolean isArkActive) { String idThesaurus = null; String idArk = ""; Statement stmt; ResultSet resultSet; try { try { stmt = conn.createStatement(); try { String query; if (identifierType.equalsIgnoreCase("1")) { // identifiants types alphanumrique ToolsHelper toolsHelper = new ToolsHelper(); idThesaurus = toolsHelper.getNewId(10); while (isThesaurusExiste(conn, idThesaurus)) { idThesaurus = toolsHelper.getNewId(10); } } else { query = "select max(id) from thesaurus"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); resultSet.next(); int idNumeriqueThesaurus = resultSet.getInt(1); idThesaurus = "" + ++idNumeriqueThesaurus; while (isThesaurusExiste(conn, idThesaurus)) { idThesaurus = "" + ++idNumeriqueThesaurus; } } /** * rcupration du code Ark via WebServices * */ if (isArkActive) { ArrayList<DcElement> dcElementsList = new ArrayList<>(); Ark_Client ark_Client = new Ark_Client(); idArk = ark_Client.getArkId(new FileUtilities().getDate(), urlSite + "?idt=" + idThesaurus, "", "", dcElementsList, "pcrt"); // pcrt : p= pactols, crt=code DCMI pour collection } query = "Insert into thesaurus (id_thesaurus," + " id_ark, created, modified)" + " values (" + "'" + idThesaurus + "'" + ",'" + idArk + "'" + "," + "current_date," + "current_date)"; stmt.executeUpdate(query); thesaurus.setId_thesaurus(idThesaurus); /* if(thesaurus.getTitle().isEmpty()) { thesaurus.setTitle("theso_" + idThesaurus); } if(!addThesaurusTraductionRollBack(conn, thesaurus)) { stmt.close(); return null; }*/ } finally { stmt.close(); } } finally { } } catch (SQLException sqle) { // Log exception log.error("Error while adding Thesaurus : " + idThesaurus, sqle); idThesaurus = null; } return idThesaurus; }
From source file:de.uniwue.info6.database.jdbc.ConnectionManager.java
/** * * * @param scenario/*from w w w. j a va2 s . c o m*/ * @param table * @return * * @throws SQLException */ private String getAutoIncrementFromTable(final Scenario scenario, String table) throws SQLException { if (scenario != null) { ResultSet resultSet = null; Statement statement = null; Connection connection = null; try { connection = instance.getConnection(scenario); statement = connection.createStatement(); statement.execute("SHOW TABLE STATUS LIKE '" + table + "'"); resultSet = statement.getResultSet(); if (resultSet.next()) { return resultSet.getString("AUTO_INCREMENT"); } } catch (Exception e) { LOGGER.error("PROBLEM GETTING TABLE CHECKSUM", e); } finally { if (resultSet != null) { resultSet.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } } return null; }
From source file:mom.trd.opentheso.bdd.helper.NoteHelper.java
/** * Cette focntion permet de retourner la liste des notes pour un concept * (type CustomNote, ScopeNote, HistoryNote) avec toutes les langues * * @param ds//from w w w. j av a 2 s .c o m * @param idConcept * @param idThesaurus * @return ArrayList des notes sous forme de Class NodeNote */ public ArrayList<NodeNote> getListNotesConceptAllLang(HikariDataSource ds, String idConcept, String idThesaurus) { ArrayList<NodeNote> nodeNotes = new ArrayList<>(); Connection conn; Statement stmt; ResultSet resultSet; StringPlus stringPlus = new StringPlus(); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT note.id, note.notetypecode," + " note.lexicalvalue, note.created," + " note.modified, note.lang FROM note, note_type" + " WHERE note.notetypecode = note_type.code" + " and note_type.isconcept = true" + " and note.id_concept = '" + idConcept + "'" + " and note.id_thesaurus = '" + idThesaurus + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); while (resultSet.next()) { NodeNote nodeNote = new NodeNote(); nodeNote.setId_concept(idConcept); nodeNote.setId_note(resultSet.getInt("id")); nodeNote.setLang(resultSet.getString("lang")); nodeNote.setLexicalvalue( stringPlus.normalizeStringForXml(resultSet.getString("lexicalvalue"))); nodeNote.setModified(resultSet.getDate("modified")); nodeNote.setCreated(resultSet.getDate("created")); nodeNote.setNotetypecode(resultSet.getString("notetypecode")); nodeNotes.add(nodeNote); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting All Notes of Concept : " + idConcept, sqle); } return nodeNotes; }
From source file:org.apache.jackrabbit.core.persistence.bundle.BundleDbPersistenceManager.java
/** * {@inheritDoc}//from www .j a v a 2 s. c o m */ public void checkConsistency(String[] uuids, boolean recursive, boolean fix) { log.info("{}: checking workspace consistency...", name); int count = 0; int total = 0; Collection modifications = new ArrayList(); if (uuids == null) { // get all node bundles in the database with a single sql statement, // which is (probably) faster than loading each bundle and traversing the tree ResultSet rs = null; try { String sql = "select count(*) from " + schemaObjectPrefix + "BUNDLE"; Statement stmt = connectionManager.executeStmt(sql, new Object[0]); try { rs = stmt.getResultSet(); if (!rs.next()) { log.error("Could not retrieve total number of bundles. empty result set."); return; } total = rs.getInt(1); } finally { closeResultSet(rs); } if (getStorageModel() == SM_BINARY_KEYS) { sql = "select NODE_ID from " + schemaObjectPrefix + "BUNDLE"; } else { sql = "select NODE_ID_HI, NODE_ID_LO from " + schemaObjectPrefix + "BUNDLE"; } stmt = connectionManager.executeStmt(sql, new Object[0]); rs = stmt.getResultSet(); // iterate over all node bundles in the db while (rs.next()) { NodeId id; if (getStorageModel() == SM_BINARY_KEYS) { id = new NodeId(new UUID(rs.getBytes(1))); } else { id = new NodeId(new UUID(rs.getLong(1), rs.getLong(2))); } // issuing 2nd statement to circumvent issue JCR-1474 ResultSet bRs = null; byte[] data = null; try { Statement bSmt = connectionManager.executeStmt(bundleSelectSQL, getKey(id.getUUID())); bRs = bSmt.getResultSet(); if (!bRs.next()) { throw new SQLException("bundle cannot be retrieved?"); } Blob blob = bRs.getBlob(1); data = getBytes(blob); } finally { closeResultSet(bRs); } try { // parse and check bundle // checkBundle will log any problems itself DataInputStream din = new DataInputStream(new ByteArrayInputStream(data)); if (binding.checkBundle(din)) { // reset stream for readBundle() din = new DataInputStream(new ByteArrayInputStream(data)); NodePropBundle bundle = binding.readBundle(din, id); checkBundleConsistency(id, bundle, fix, modifications); } else { log.error("invalid bundle '" + id + "', see previous BundleBinding error log entry"); } } catch (Exception e) { log.error("Error in bundle " + id + ": " + e); } count++; if (count % 1000 == 0) { log.info(name + ": checked " + count + "/" + total + " bundles..."); } } } catch (Exception e) { log.error("Error loading bundle", e); } finally { closeResultSet(rs); total = count; } } else { // check only given uuids, handle recursive flag // 1) convert uuid array to modifiable list // 2) for each uuid do // a) load node bundle // b) check bundle, store any bundle-to-be-modified in collection // c) if recursive, add child uuids to list of uuids List uuidList = new ArrayList(uuids.length); // convert uuid string array to list of UUID objects for (int i = 0; i < uuids.length; i++) { try { uuidList.add(new UUID(uuids[i])); } catch (IllegalArgumentException e) { log.error("Invalid uuid for consistency check, skipping: '" + uuids[i] + "': " + e); } } // iterate over UUIDs (including ones that are newly added inside the loop!) for (int i = 0; i < uuidList.size(); i++) { final UUID uuid = (UUID) uuidList.get(i); try { // load the node from the database NodeId id = new NodeId(uuid); NodePropBundle bundle = loadBundle(id, true); if (bundle == null) { log.error("No bundle found for uuid '" + uuid + "'"); continue; } checkBundleConsistency(id, bundle, fix, modifications); if (recursive) { Iterator iter = bundle.getChildNodeEntries().iterator(); while (iter.hasNext()) { NodePropBundle.ChildNodeEntry entry = (NodePropBundle.ChildNodeEntry) iter.next(); uuidList.add(entry.getId().getUUID()); } } count++; if (count % 1000 == 0) { log.info(name + ": checked " + count + "/" + uuidList.size() + " bundles..."); } } catch (ItemStateException e) { // problem already logged (loadBundle called with logDetailedErrors=true) } } total = uuidList.size(); } // repair collected broken bundles if (fix && !modifications.isEmpty()) { log.info(name + ": Fixing " + modifications.size() + " inconsistent bundle(s)..."); Iterator iterator = modifications.iterator(); while (iterator.hasNext()) { NodePropBundle bundle = (NodePropBundle) iterator.next(); try { log.info(name + ": Fixing bundle '" + bundle.getId() + "'"); bundle.markOld(); // use UPDATE instead of INSERT storeBundle(bundle); evictBundle(bundle.getId()); } catch (ItemStateException e) { log.error(name + ": Error storing fixed bundle: " + e); } } } log.info(name + ": checked " + count + "/" + total + " bundles."); }
From source file:org.jumpmind.db.sql.JdbcSqlTemplate.java
public int update(final boolean autoCommit, final boolean failOnError, final boolean failOnDrops, final boolean failOnSequenceCreate, final int commitRate, final ISqlResultsListener resultsListener, final ISqlStatementSource source) { return execute(new IConnectionCallback<Integer>() { @SuppressWarnings("resource") public Integer execute(Connection con) throws SQLException { int totalUpdateCount = 0; boolean oldAutoCommitSetting = con.getAutoCommit(); Statement stmt = null; try { con.setAutoCommit(autoCommit); stmt = con.createStatement(); int statementCount = 0; for (String statement = source.readSqlStatement(); statement != null; statement = source .readSqlStatement()) { logSql(statement, null); try { boolean hasResults = stmt.execute(statement); int updateCount = stmt.getUpdateCount(); totalUpdateCount += updateCount; int rowsRetrieved = 0; if (hasResults) { ResultSet rs = null; try { rs = stmt.getResultSet(); while (rs.next()) { rowsRetrieved++; }// ww w.j a v a 2s . c o m } finally { close(rs); } } if (resultsListener != null) { resultsListener.sqlApplied(statement, updateCount, rowsRetrieved, statementCount); } statementCount++; if (statementCount % commitRate == 0 && !autoCommit) { con.commit(); } } catch (SQLException ex) { boolean isDrop = statement.toLowerCase().trim().startsWith("drop"); boolean isSequenceCreate = statement.toLowerCase().trim().startsWith("create sequence"); if (resultsListener != null) { resultsListener.sqlErrored(statement, translate(statement, ex), statementCount, isDrop, isSequenceCreate); } if ((isDrop && !failOnDrops) || (isSequenceCreate && !failOnSequenceCreate)) { log.debug("{}. Failed to execute: {}", ex.getMessage(), statement); } else { log.warn("{}. Failed to execute: {}", ex.getMessage(), statement); if (failOnError) { throw ex; } } } } if (!autoCommit) { con.commit(); } return totalUpdateCount; } catch (SQLException ex) { if (!autoCommit) { con.rollback(); } throw ex; } finally { close(stmt); if (!con.isClosed()) { con.setAutoCommit(oldAutoCommitSetting); } } } }); }
From source file:mom.trd.opentheso.bdd.helper.NoteHelper.java
/** * Cette focntion permet de retourner la liste de l'historique des notes * pour un concept (type CustomNote, ScopeNote, HistoryNote) une date * prcise//from ww w . ja v a2 s . c o m * * @param ds * @param idConcept * @param idThesaurus * @param idTerm * @param idLang * @param date * @return ArrayList des notes sous forme de Class NodeNote */ public ArrayList<NodeNote> getNoteHistoriqueFromDate(HikariDataSource ds, String idConcept, String idThesaurus, String idTerm, String idLang, Date date) { ArrayList<NodeNote> nodeNotes = new ArrayList<>(); Connection conn; Statement stmt; ResultSet resultSet; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT id, notetypecode, lexicalvalue, modified, username FROM note_historique, users" + " WHERE id_thesaurus = '" + idThesaurus + "'" + " and lang ='" + idLang + "'" + " and (id_concept = '" + idConcept + "' OR id_term = '" + idTerm + "' )" + " and note_historique.id_user=users.id_user" + " and modified <= '" + date.toString() + "' order by modified DESC"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); while (resultSet.next()) { boolean exist = false; for (NodeNote nn : nodeNotes) { if (nn.getNotetypecode().equals(resultSet.getString("notetypecode"))) { if (nn.getModified().before(resultSet.getDate("modified"))) { NodeNote nodeNote = new NodeNote(); nodeNote.setId_concept(idConcept); nodeNote.setId_term(idTerm); nodeNote.setId_note(resultSet.getInt("id")); nodeNote.setLang(idLang); nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue")); nodeNote.setModified(resultSet.getDate("modified")); nodeNote.setNotetypecode(resultSet.getString("notetypecode")); nodeNote.setIdUser(resultSet.getString("username")); nodeNotes.add(nodeNote); } exist = true; } } if (!exist) { NodeNote nodeNote = new NodeNote(); nodeNote.setId_concept(idConcept); nodeNote.setId_term(idTerm); nodeNote.setId_note(resultSet.getInt("id")); nodeNote.setLang(idLang); nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue")); nodeNote.setModified(resultSet.getDate("modified")); nodeNote.setNotetypecode(resultSet.getString("notetypecode")); nodeNote.setIdUser(resultSet.getString("username")); nodeNotes.add(nodeNote); } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting date historique Notes of Concept : " + idConcept, sqle); } return nodeNotes; }
From source file:org.plasma.sdo.jdbc.service.GraphQuery.java
private int countResults(Connection con, Query query, PlasmaType type) { int result = 0; Object[] params = new Object[0]; FilterAssembler filterAssembler = null; StringBuilder sqlQuery = new StringBuilder(); AliasMap aliasMap = new AliasMap(type); sqlQuery.append("SELECT COUNT(*)"); sqlQuery.append(aliasMap.getAlias(type)); Statement statement = null; ResultSet rs = null;// ww w. j a v a2 s. c o m try { Where where = query.findWhereClause(); if (where != null) { filterAssembler = new FilterAssembler(where, type, aliasMap); sqlQuery.append(" "); sqlQuery.append(filterAssembler.getFilter()); params = filterAssembler.getParams(); if (log.isDebugEnabled()) { log.debug("filter: " + filterAssembler.getFilter()); } } else { sqlQuery.append(" FROM "); sqlQuery.append(getQualifiedPhysicalName(type)); sqlQuery.append(" "); sqlQuery.append(aliasMap.getAlias(type)); } if (query.getStartRange() != null && query.getEndRange() != null) log.warn("query range (start: " + query.getStartRange() + ", end: " + query.getEndRange() + ") ignored for count operation"); if (log.isDebugEnabled()) { log.debug("queryString: " + sqlQuery.toString()); log.debug("executing..."); } statement = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); statement.execute(sqlQuery.toString()); rs = statement.getResultSet(); rs.first(); result = rs.getInt(1); } catch (Throwable t) { StringBuffer buf = this.generateErrorDetail(t, sqlQuery.toString(), filterAssembler); log.error(buf.toString()); throw new DataAccessException(t); } finally { try { if (rs != null) rs.close(); if (statement != null) statement.close(); } catch (SQLException e) { log.error(e.getMessage(), e); } } return result; }
From source file:mom.trd.opentheso.bdd.helper.RelationsHelper.java
/** * Cette fonction permet de savoir si le Concept a une relation NT si oui, * on ne le supprime pas pour viter de supprimer toute la chaine * * @param ds//from ww w.ja va2s . com * @param idConcept * @param idThesaurus * @return Objet class Concept */ public boolean isRelationNTExist(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_concept2 from hierarchical_relationship" + " where id_thesaurus = '" + idThesaurus + "'" + " and id_concept1 = '" + idConcept + "'" + " and role = '" + "NT" + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); existe = resultSet.next(); } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while asking if relation NT exist of Concept : " + idConcept, sqle); } return existe; }