List of usage examples for java.sql Statement getResultSet
ResultSet getResultSet() throws SQLException;
ResultSet
object. From source file:mom.trd.opentheso.bdd.helper.ThesaurusHelper.java
/** * Cette fonction permet de savoir si le terme existe ou non * * @param ds/*from ww w.jav a 2 s . c om*/ * @param idThesaurus * @param idLang * @return boolean */ public boolean isLanguageExistOfThesaurus(HikariDataSource ds, String idThesaurus, String idLang) { 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_thesaurus from thesaurus_label where " + " id_thesaurus ='" + idThesaurus + "'" + " and lang = '" + idLang + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); 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 Language exist of Thesaurus : " + idThesaurus, sqle); } return existe; }
From source file:vitro.vspEngine.service.persistence.DBCommons.java
synchronized public void updateRcvGatewayAdTimestamp(String pGatewayRegisteredName, boolean removeTimeStampFlag) { java.sql.Connection conn = null; try {/* w ww . j a v a 2s .c om*/ Class.forName(jdbcdriverClassName).newInstance(); conn = DriverManager.getConnection(connString, usrStr, pwdStr); String echomessage = ""; if (!conn.isClosed()) { //echomessage = "Successfully connected to "+ "MySQL server using TCP/IP..."; Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(); if (!removeTimeStampFlag) { if (stmt.execute("UPDATE `" + dbSchemaStr + "`.`registeredgateway` SET lastadvtimestamp = UNIX_TIMESTAMP(now()) WHERE registeredName=\'" + pGatewayRegisteredName + "\'")) { rs = stmt.getResultSet(); // TODO: this is not needed here... } } else { if (stmt.execute("UPDATE `" + dbSchemaStr + "`.`registeredgateway` SET lastadvtimestamp = 0 WHERE registeredName=\'" + pGatewayRegisteredName + "\'")) { rs = stmt.getResultSet(); // TODO: this is not needed here... } } } catch (SQLException ex) { // handle any errors System.err.println("SQLException3: " + ex.getMessage()); System.err.println("SQLState3: " + ex.getSQLState()); System.err.println("VendorError3: " + ex.getErrorCode()); } finally { // it is a good idea to release // resources in a finally{} block // in reverse-order of their creation // if they are no-longer needed if (rs != null) { try { rs.close(); } catch (SQLException sqlEx) { } // ignore rs = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException sqlEx) { } // ignore stmt = null; } } } else { echomessage = "Error accessing DB server..."; } // DEBUG //System.out.println(echomessage); } catch (Exception e) { System.err.println("Exception: " + e.getMessage()); } finally { try { if (conn != null) conn.close(); } catch (SQLException e) { } } }
From source file:migration.ProjektMigration.java
/** * Creates the rechnung./* w ww . j ava2 s . co m*/ */ public void createRechnung() { String load_sql; Statement load_stmt; ResultSet load_rs; String store_sql; PreparedStatement store_prepstmt; final ResultSet store_rs; try { load_sql = "SELECT Rechnungsbetrag, Bezugsform, Bezugsjahr, Sigel, Exemplar, ExImportID FROM ExRechnungstabelle"; load_stmt = this.leg_con.createStatement(); store_sql = "insert into Rechnung (betrag, bezugsform, bezugsjahr, exemplar_exemplarId) values (?, ?, ?, ?)";// , // sigel_sigelId store_prepstmt = this.tgt_con.prepareStatement(store_sql); // evtl. // brauchen // wir // was // in // Richtung: // Statement.RETURN_GENERATED_KEYS // logger.info("Lese von ExRechnungstabelle"); load_stmt.execute(load_sql); load_rs = load_stmt.getResultSet(); // logger.info("Schreibe nach Rechnung"); while (load_rs.next()) { store_prepstmt.setInt(1, load_rs.getInt("Rechnungsbetrag")); store_prepstmt.setString(2, load_rs.getString("Bezugsform")); store_prepstmt.setString(3, load_rs.getString("Bezugsjahr")); int tmp = this.help.getIdFromIntArray(this.getExemplare(), load_rs.getInt("Exemplar")); if (tmp > 0) { store_prepstmt.setLong(4, tmp); } else { store_prepstmt.setNull(4, java.sql.Types.BIGINT); } tmp = this.help.getIdFromStringArray(this.help.getSigel(), load_rs.getString("Sigel")); // store_prepstmt.setLong(5, (long)tmp); 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.FacetHelper.java
/** * Cette fonction permet de retourner toutes les Facettes d'un thsaurus * sous forme de NodeFacet/*from ww w . j a v a 2 s . com*/ * * @param ds * @param idThesaurus * @param idLang * @return ArrayList de NodeFacet */ public ArrayList<NodeFacet> getAllFacetsOfThesaurus(HikariDataSource ds, String idThesaurus, String idLang) { Connection conn; Statement stmt; ResultSet resultSet; ArrayList<NodeFacet> nodeFacetlist = new ArrayList(); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT node_label.lexical_value," + " node_label.facet_id, thesaurus_array.id_concept_parent FROM " + " thesaurus_array, node_label WHERE" + " thesaurus_array.facet_id = node_label.facet_id AND" + " thesaurus_array.id_thesaurus = node_label.id_thesaurus" + " and node_label.lang = '" + idLang + "'" + " and node_label.id_thesaurus = '" + idThesaurus + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); while (resultSet.next()) { NodeFacet nodeFacet = new NodeFacet(); nodeFacet.setIdFacet(resultSet.getInt("facet_id")); nodeFacet.setLexicalValue(resultSet.getString("lexical_value")); nodeFacet.setIdConceptParent(resultSet.getString("id_concept_parent")); nodeFacetlist.add(nodeFacet); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting All Facet of Thesaurus : " + idThesaurus, sqle); } return nodeFacetlist; }
From source file:org.apache.jackrabbit.core.persistence.bundle.BundleDbPersistenceManager.java
/** * {@inheritDoc}// www.ja v a 2 s. c o m */ protected synchronized boolean existsBundle(NodeId id) throws ItemStateException { ResultSet rs = null; try { Statement stmt = connectionManager.executeStmt(bundleSelectSQL, getKey(id.getUUID())); rs = stmt.getResultSet(); // a bundle exists, if the result has at least one entry return rs.next(); } catch (Exception e) { String msg = "failed to check existence of bundle: " + id; log.error(msg, e); throw new ItemStateException(msg, e); } finally { closeResultSet(rs); } }
From source file:mom.trd.opentheso.bdd.helper.ThesaurusHelper.java
/** * retourne la liste des thsaurus d'un utilisateur * @param ds//from ww w . j a va 2 s . c om * @param idUser * @param idLang * @return */ public Map getListThesaurusOfUser(HikariDataSource ds, int idUser, String idLang) { Connection conn; Statement stmt; ResultSet resultSet; Map map = new HashMap(); ArrayList tabIdThesaurus = new ArrayList(); try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT DISTINCT user_role.id_thesaurus FROM" + " user_role WHERE" + " id_user = " + idUser; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { while (resultSet.next()) { if (!resultSet.getString("id_thesaurus").isEmpty()) tabIdThesaurus.add(resultSet.getString("id_thesaurus")); } for (Object tabIdThesauru : tabIdThesaurus) { query = "select title from thesaurus_label where" + " id_thesaurus = '" + tabIdThesauru + "'" + " and lang = '" + idLang + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { resultSet.next(); if (resultSet.getRow() == 0) { map.put("(" + tabIdThesauru + ")", tabIdThesauru); } else { map.put(resultSet.getString("title") + "(" + tabIdThesauru + ")", tabIdThesauru); } } else { } } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting Map of thesaurus : " + map.toString(), sqle); } return map; }
From source file:com.sterlingcommerce.xpedx.webchannel.services.XPEDXGetAllReportsAction.java
public void getConnection() throws SQLException { String XCOM_MST_CUST = getCustomerNo(getWCContext().getBuyerOrgCode()); String DBUrl = YFSSystem.getProperty("datasource_url"); String DBName = YFSSystem.getProperty("datasource_name"); //String DBUrl= "t3://localhost:7002"; //String DBName= "SeptJNDI"; Connection connection = null; Statement stmt = null; ResultSet rs = null;/*from www . ja v a2 s. c o m*/ XPEDXReportBean rpBean = null; try { Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); ht.put("java.naming.provider.url", DBUrl); Context env = new InitialContext(ht); //InitialContext context = new InitialContext(ht); DataSource dataSource = (DataSource) env.lookup(DBName); connection = dataSource.getConnection(); if (log.isDebugEnabled()) { log.debug("Connection successful.."); } //String schemaName=YFSSystem.getProperty("schemaname"); //String Query="select distinct RPT_CUID, RPT_NAME,RPT_ID,RPT_KIND, RPT_DESC from " + schemaName + ".xpedx_custom_rpt_dtl where XCOM_MST_CUST=" + "'"+ XCOM_MST_CUST +"'"+"AND CUST_ROLE in ("; String Query = "select distinct RPT_CUID, RPT_NAME,RPT_ID,RPT_KIND, RPT_DESC from DH.xpedx_custom_rpt_dtl where XCOM_MST_CUST=" + "'" + XCOM_MST_CUST + "'" + "AND CUST_ROLE in ("; Query = getUserRole(Query); stmt = connection.createStatement(); boolean test = stmt.execute(Query); dataExchangeReportList = new ArrayList<Report>(); if (test == true) { rs = stmt.getResultSet(); while (rs.next()) { Report report = new Report(); report.setCuid(rs.getString("RPT_CUID")); report.setName(rs.getString("RPT_NAME")); report.setKind(rs.getString("RPT_KIND")); report.setId(rs.getInt("RPT_ID")); report.setDescription(rs.getString("RPT_DESC")); dataExchangeReportList.add(report); } } } catch (Exception e) { LOG.debug("Not able to connect to DEV Datasource:->" + e.getMessage()); } finally { stmt.close(); connection.close(); } }
From source file:vitro.vspEngine.service.persistence.DBCommons.java
public Vector<DBRegisteredGateway> getRegisteredGatewayEntries() { Vector<DBRegisteredGateway> retVect = new Vector<DBRegisteredGateway>(); java.sql.Connection conn = null; try {//from w ww . j av a 2 s .c o m Class.forName(jdbcdriverClassName).newInstance(); conn = DriverManager.getConnection(connString, usrStr, pwdStr); String echomessage = ""; if (!conn.isClosed()) { //echomessage = "Successfully connected to "+ "MySQL server using TCP/IP..."; Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(); if (stmt.execute( "SELECT idregisteredgateway, registeredName, friendlyName, friendlyDescription, ip, listeningport, lastadvtimestamp, disabled, FROM_UNIXTIME(lastadvtimestamp, \'%d/%m/%Y %H:%i:%s\') lastdate FROM `" + dbSchemaStr + "`.`registeredgateway` ")) { rs = stmt.getResultSet(); } if (rs != null) { while (rs.next()) { int gateId = rs.getInt("idregisteredgateway"); String registeredName = rs.getString("registeredName") == null ? "" : rs.getString("registeredName"); // this is the one used in registration messages String friendlyName = rs.getString("friendlyName") == null ? "" : rs.getString("friendlyName"); String friendlyDescription = rs.getString("friendlyDescription") == null ? "" : rs.getString("friendlyDescription"); String gateIp = rs.getString("ip") == null ? "" : rs.getString("ip"); String gatePort = rs.getString("listeningport") == null ? "" : rs.getString("listeningport"); int lastadvtimestampInt = rs.getInt("lastadvtimestamp"); String lastdate = rs.getString("lastdate") == null ? "N/A" : rs.getString("lastdate"); Boolean status = rs.getBoolean("disabled"); if (!registeredName.isEmpty() && !registeredName.equalsIgnoreCase("")) { DBRegisteredGateway entryRegisterGateway = new DBRegisteredGateway(gateId, registeredName, friendlyName, friendlyDescription, gateIp, gatePort, lastadvtimestampInt, lastdate, status); retVect.addElement(entryRegisterGateway); } } } } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } finally { // it is a good idea to release // resources in a finally{} block // in reverse-order of their creation // if they are no-longer needed if (rs != null) { try { rs.close(); } catch (SQLException sqlEx) { System.out.println("SQLException on rs close(): " + sqlEx.getMessage()); } // ignore rs = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException sqlEx) { System.out.println("SQLException on stmt close(): " + sqlEx.getMessage()); } // ignore stmt = null; } } } else { echomessage = "Error accessing DB server..."; } System.out.println(echomessage); } catch (Exception e) { System.err.println("Exception: " + e.getMessage()); } finally { try { if (conn != null) conn.close(); } catch (SQLException e) { } } return retVect; }
From source file:vitro.vspEngine.service.persistence.DBCommons.java
synchronized public void updateStatus(String pGatewayRegisteredName) { java.sql.Connection conn = null; try {/*from ww w . ja v a 2 s . com*/ String echomessage = ""; Class.forName(jdbcdriverClassName).newInstance(); conn = DriverManager.getConnection(connString, usrStr, pwdStr); if (!conn.isClosed()) { Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(); if (stmt.execute( "SELECT idregisteredgateway, registeredName, friendlyName, friendlyDescription, ip, listeningport, lastadvtimestamp, disabled, FROM_UNIXTIME(lastadvtimestamp, \'%d/%m/%Y %H:%i:%s\') lastdate FROM `" + dbSchemaStr + "`.`registeredgateway` ")) { rs = stmt.getResultSet(); } if (rs != null) { while (rs.next()) { int gateId = rs.getInt("idregisteredgateway"); String registeredName = rs.getString("registeredName") == null ? "" : rs.getString("registeredName"); // this is the one used in registration messages String friendlyName = rs.getString("friendlyName") == null ? "" : rs.getString("friendlyName"); String friendlyDescription = rs.getString("friendlyDescription") == null ? "" : rs.getString("friendlyDescription"); String gateIp = rs.getString("ip") == null ? "" : rs.getString("ip"); String gatePort = rs.getString("listeningport") == null ? "" : rs.getString("listeningport"); int lastadvtimestampInt = rs.getInt("lastadvtimestamp"); String lastdate = rs.getString("lastdate") == null ? "N/A" : rs.getString("lastdate"); Boolean status = rs.getBoolean("disabled"); if (registeredName.equalsIgnoreCase(pGatewayRegisteredName)) { if (status == false) { if (stmt.execute("UPDATE `" + dbSchemaStr + "`.`registeredgateway` SET disabled = 1 WHERE registeredName=\'" + pGatewayRegisteredName + "\'")) { rs = stmt.getResultSet(); // TODO: this is not needed here... } } else { if (stmt.execute("UPDATE `" + dbSchemaStr + "`.`registeredgateway` SET disabled = 0 WHERE registeredName=\'" + pGatewayRegisteredName + "\'")) { rs = stmt.getResultSet(); // TODO: this is not needed here... } } break; } } } } catch (SQLException ex) { // handle any errors System.err.println("SQLException3: " + ex.getMessage()); System.err.println("SQLState3: " + ex.getSQLState()); System.err.println("VendorError3: " + ex.getErrorCode()); } finally { // it is a good idea to release // resources in a finally{} block // in reverse-order of their creation // if they are no-longer needed if (rs != null) { try { rs.close(); } catch (SQLException sqlEx) { } // ignore rs = null; } if (stmt != null) { try { stmt.close(); } catch (SQLException sqlEx) { } // ignore stmt = null; } } } else { echomessage = "Error accessing DB server..."; } // DEBUG //System.out.println(echomessage); } catch (Exception e) { System.err.println("Exception: " + e.getMessage()); } finally { try { if (conn != null) conn.close(); } catch (SQLException e) { } } }
From source file:org.apache.jackrabbit.core.persistence.bundle.BundleDbPersistenceManager.java
/** * {@inheritDoc}//from www . ja va 2s.c om */ public synchronized NodeIdIterator getAllNodeIds(NodeId bigger, int maxCount) throws ItemStateException, RepositoryException { ResultSet rs = null; try { UUID lowUuid; Object[] keys; String sql; if (bigger == null) { sql = bundleSelectAllIdsSQL; lowUuid = null; keys = new Object[0]; } else { sql = bundleSelectAllIdsFromSQL; lowUuid = bigger.getUUID(); keys = getKey(lowUuid); } if (maxCount > 0) { // get some more rows, in case the first row is smaller // only required for SM_LONGLONG_KEYS // probability is very low to get get the wrong first key, < 1 : 2^64 // see also bundleSelectAllIdsFrom SQL statement maxCount += 10; } Statement stmt = connectionManager.executeStmt(sql, keys, false, maxCount); rs = stmt.getResultSet(); ArrayList result = new ArrayList(); while ((maxCount == 0 || result.size() < maxCount) && rs.next()) { UUID current; if (getStorageModel() == SM_BINARY_KEYS) { current = new UUID(rs.getBytes(1)); } else { long high = rs.getLong(1); long low = rs.getLong(2); current = new UUID(high, low); } if (lowUuid != null) { // skip the keys that are smaller or equal (see above, maxCount += 10) if (current.compareTo(lowUuid) <= 0) { continue; } } result.add(current); } ListNodeIdIterator it = new ListNodeIdIterator(result); return it; } catch (SQLException e) { String msg = "getAllNodeIds failed."; log.error(msg, e); throw new ItemStateException(msg, e); } finally { closeResultSet(rs); } }