List of usage examples for java.sql ResultSet getDate
java.sql.Date getDate(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Date
object in the Java programming language. From source file:com.wso2telco.dep.reportingservice.dao.BillingDAO.java
/** * Gets the total api traffic for line chart. * * @param fromDate the from date/*w w w. j a v a 2 s.com*/ * @param toDate the to date * @param subscriber the subscriber * @param operator the operator * @param applicationId the application id * @param api the api * @return the total api traffic for line chart * @throws Exception the exception */ public List<String[]> getTotalAPITrafficForLineChart(String fromDate, String toDate, String subscriber, String operator, int applicationId, String api) throws Exception { String consumerKey = null; if (subscriber.equals("__ALL__")) { subscriber = "%"; } if (operator.equals("__ALL__")) { operator = "%"; } if (applicationId == 0) { consumerKey = "%"; } else { consumerKey = apiManagerDAO.getConsumerKeyByApplication(applicationId); } if (api.equals("__ALL__")) { api = "%"; } if (consumerKey == null) { return null; } Connection conn = null; PreparedStatement ps = null; ResultSet results = null; StringBuilder sql = new StringBuilder(); sql.append("select date(time) as date, sum(response_count) hits from ") .append(ReportingTable.SB_API_RESPONSE_SUMMARY.getTObject()) .append(" where DATE(time) between STR_TO_DATE(?,'%Y-%m-%d') and STR_TO_DATE(?,'%Y-%m-%d') AND operatorId LIKE ? AND userId LIKE ? AND API LIKE ? AND consumerKey LIKE ? ") .append("group by date"); List<String[]> api_request = new ArrayList<String[]>(); try { conn = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB); ps = conn.prepareStatement(sql.toString()); ps.setString(1, fromDate); ps.setString(2, toDate); ps.setString(3, operator); ps.setString(4, subscriber); ps.setString(5, api); ps.setString(6, consumerKey); if (log.isDebugEnabled()) { log.debug("getTotalTrafficForLineChart : SQL " + ps.toString()); } results = ps.executeQuery(); while (results.next()) { String[] temp = { results.getDate(1).toString(), results.getString(2) }; api_request.add(temp); } } catch (Exception e) { handleException("getTotalAPITrafficForLineChart", e); } finally { DbUtils.closeAllConnections(ps, conn, results); } return api_request; }
From source file:org.apache.ddlutils.platform.PlatformImplBase.java
/** * This is the core method to retrieve a value for a column from a result set. Its primary * purpose is to call the appropriate method on the result set, and to provide an extension * point where database-specific implementations can change this behavior. * /* www . jav a 2 s.c om*/ * @param resultSet The result set to extract the value from * @param columnName The name of the column; can be <code>null</code> in which case the * <code>columnIdx</code> will be used instead * @param columnIdx The index of the column's value in the result set; is only used if * <code>columnName</code> is <code>null</code> * @param jdbcType The jdbc type to extract * @return The value * @throws SQLException If an error occurred while accessing the result set */ protected Object extractColumnValue(ResultSet resultSet, String columnName, int columnIdx, int jdbcType) throws SQLException { boolean useIdx = (columnName == null); Object value; switch (jdbcType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: value = useIdx ? resultSet.getString(columnIdx) : resultSet.getString(columnName); break; case Types.NUMERIC: case Types.DECIMAL: value = useIdx ? resultSet.getBigDecimal(columnIdx) : resultSet.getBigDecimal(columnName); break; case Types.BIT: case Types.BOOLEAN: value = new Boolean(useIdx ? resultSet.getBoolean(columnIdx) : resultSet.getBoolean(columnName)); break; case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: value = new Integer(useIdx ? resultSet.getInt(columnIdx) : resultSet.getInt(columnName)); break; case Types.BIGINT: value = new Long(useIdx ? resultSet.getLong(columnIdx) : resultSet.getLong(columnName)); break; case Types.REAL: value = new Float(useIdx ? resultSet.getFloat(columnIdx) : resultSet.getFloat(columnName)); break; case Types.FLOAT: case Types.DOUBLE: value = new Double(useIdx ? resultSet.getDouble(columnIdx) : resultSet.getDouble(columnName)); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: value = useIdx ? resultSet.getBytes(columnIdx) : resultSet.getBytes(columnName); break; case Types.DATE: value = useIdx ? resultSet.getDate(columnIdx) : resultSet.getDate(columnName); break; case Types.TIME: value = useIdx ? resultSet.getTime(columnIdx) : resultSet.getTime(columnName); break; case Types.TIMESTAMP: value = useIdx ? resultSet.getTimestamp(columnIdx) : resultSet.getTimestamp(columnName); break; case Types.CLOB: Clob clob = useIdx ? resultSet.getClob(columnIdx) : resultSet.getClob(columnName); if (clob == null) { value = null; } else { long length = clob.length(); if (length > Integer.MAX_VALUE) { value = clob; } else if (length == 0) { // the javadoc is not clear about whether Clob.getSubString // can be used with a substring length of 0 // thus we do the safe thing and handle it ourselves value = ""; } else { value = clob.getSubString(1l, (int) length); } } break; case Types.BLOB: Blob blob = useIdx ? resultSet.getBlob(columnIdx) : resultSet.getBlob(columnName); if (blob == null) { value = null; } else { long length = blob.length(); if (length > Integer.MAX_VALUE) { value = blob; } else if (length == 0) { // the javadoc is not clear about whether Blob.getBytes // can be used with for 0 bytes to be copied // thus we do the safe thing and handle it ourselves value = new byte[0]; } else { value = blob.getBytes(1l, (int) length); } } break; case Types.ARRAY: value = useIdx ? resultSet.getArray(columnIdx) : resultSet.getArray(columnName); break; case Types.REF: value = useIdx ? resultSet.getRef(columnIdx) : resultSet.getRef(columnName); break; default: value = useIdx ? resultSet.getObject(columnIdx) : resultSet.getObject(columnName); break; } return resultSet.wasNull() ? null : value; }
From source file:com.wso2telco.dep.reportingservice.dao.BillingDAO.java
/** * Gets the all response times for ap iby date. * * @param operator the operator//from ww w .j ava 2 s .c o m * @param userId the user id * @param fromDate the from date * @param toDate the to date * @param api the api * @return the all response times for ap iby date * @throws Exception the exception */ public List<APIResponseDTO> getAllResponseTimesForAPIbyDate(String operator, String userId, String fromDate, String toDate, String api) throws Exception { if (log.isDebugEnabled()) { log.debug("getAllResponseTimesForAllAPIs() for Operator " + operator + " Subscriber " + userId + " betweeen " + fromDate + " to " + toDate); } if (operator.contains("__ALL__")) { operator = "%"; } if (userId.contains("__ALL__")) { userId = "%"; } Connection connection = null; PreparedStatement ps = null; ResultSet results = null; StringBuilder sql = new StringBuilder(); sql.append( "SELECT api,SUM(response_count) as sumCount, SUM(serviceTime) as sumServiceTime, STR_TO_DATE(time,'%Y-%m-%d') as date FROM ") .append(ReportingTable.SB_API_RESPONSE_SUMMARY.getTObject()) .append(" WHERE api=? AND (time BETWEEN ? AND ?) AND operatorId LIKE ? AND userId LIKE ? GROUP BY date;"); List<APIResponseDTO> responseTimes = new ArrayList<APIResponseDTO>(); try { connection = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB); ps = connection.prepareStatement(sql.toString()); ps.setString(1, api); ps.setString(2, fromDate + " 00:00:00"); ps.setString(3, toDate + " 23:59:59"); ps.setString(4, operator); ps.setString(5, userId); results = ps.executeQuery(); while (results.next()) { APIResponseDTO resp = new APIResponseDTO(); resp.setApiVersion(results.getString("api")); resp.setResponseCount(results.getInt("sumCount")); resp.setServiceTime(results.getInt("sumServiceTime")); resp.setDate(results.getDate("date")); responseTimes.add(resp); } } catch (Exception e) { handleException("getAllResponseTimesForAPIbyDate", e); } finally { DbUtils.closeAllConnections(ps, connection, results); } return responseTimes; }
From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java
/** * Cette fonction permet de rcuprer un Concept par son id et son thsaurus * sous forme de classe Concept (sans les relations) ni le Terme * * @param ds/*from w w w . j a v a 2 s . c om*/ * @param idConcept * @param idThesaurus * @return Objet class Concept */ public Concept getThisConcept(HikariDataSource ds, String idConcept, String idThesaurus) { Connection conn; Statement stmt; ResultSet resultSet; Concept concept = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "select * from concept where id_thesaurus = '" + idThesaurus + "'" + " and id_concept = '" + idConcept + "'"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); resultSet.next(); if (resultSet.getRow() != 0) { concept = new Concept(); concept.setIdConcept(idConcept); concept.setIdThesaurus(idThesaurus); concept.setIdArk(resultSet.getString("id_ark")); concept.setCreated(resultSet.getDate("created")); concept.setModified(resultSet.getDate("modified")); concept.setStatus(resultSet.getString("status")); concept.setNotation(resultSet.getString("notation")); concept.setTopConcept(resultSet.getBoolean("top_concept")); concept.setIdGroup(resultSet.getString("id_group")); } resultSet.close(); } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting Concept : " + idConcept, sqle); } return concept; }
From source file:com.wso2telco.dep.reportingservice.dao.BillingDAO.java
/** * Gets the all response times for api./* w ww .j a v a2s.c o m*/ * * @param operator the operator * @param appId the app id * @param apiVersion the api version * @param fromDate the from date * @param toDate the to date * @return the all response times for api * @throws Exception the exception */ public List<APIResponseDTO> getAllResponseTimesForAPI(String operator, String appId, String apiVersion, String fromDate, String toDate) throws Exception { String appConsumerKey = "%"; if (operator.contains("__ALL__")) { operator = "%"; } if (!appId.contains("__ALL__")) { appConsumerKey = getConsumerKeyByAppId(appId); } Connection connection = null; PreparedStatement ps = null; ResultSet results = null; StringBuilder sql = new StringBuilder(); sql.append( "select api_version,response_count AS count, serviceTime,STR_TO_DATE(time,'%Y-%m-%d') as date FROM ") .append(ReportingTable.SB_API_RESPONSE_SUMMARY.getTObject()) .append(" WHERE api_version=? AND (time BETWEEN ? AND ?) AND operatorId LIKE ? AND consumerKey LIKE ?;"); List<APIResponseDTO> responseTimes = new ArrayList<APIResponseDTO>(); try { connection = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB); ps = connection.prepareStatement(sql.toString()); log.debug("getAllResponseTimesForAPI for apiVersion---> " + apiVersion); ps.setString(1, apiVersion); ps.setString(2, fromDate + " 00:00:00"); ps.setString(3, toDate + " 23:59:59"); ps.setString(4, operator); ps.setString(5, appConsumerKey); log.debug("SQL (PS) ---> " + ps.toString()); results = ps.executeQuery(); while (results.next()) { APIResponseDTO resp = new APIResponseDTO(); resp.setApiVersion(results.getString("api_version")); resp.setResponseCount(results.getInt("count")); resp.setServiceTime(results.getInt("serviceTime")); resp.setDate(results.getDate("date")); responseTimes.add(resp); } } catch (Exception e) { handleException("getAllResponseTimesForAPI", e); } finally { DbUtils.closeAllConnections(ps, connection, results); } return responseTimes; }
From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java
/** * Cette fonction permet de rcuprer l'historique d'un concept * * @param ds// www.ja v a 2 s . c o m * @param idConcept * @param idThesaurus * @return String idGroup */ public ArrayList<Concept> getConceptHisoriqueAll(HikariDataSource ds, String idConcept, String idThesaurus) { ArrayList<Concept> listeConcept = new ArrayList<>(); Connection conn; Statement stmt; ResultSet resultSet; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT modified, status, notation, top_concept, id_group, username from concept_historique, users where id_thesaurus = '" + idThesaurus + "'" + " and id_concept = '" + idConcept + "'" + " and concept_historique.id_user=users.id_user" + " order by modified DESC"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { while (resultSet.next()) { Concept c = new Concept(); c.setIdConcept(idConcept); c.setIdThesaurus(idThesaurus); c.setModified(resultSet.getDate("modified")); c.setStatus(resultSet.getString("status")); c.setNotation(resultSet.getString("notation")); c.setTopConcept(resultSet.getBoolean("top_concept")); c.setIdGroup(resultSet.getString("id_group")); c.setUserName(resultSet.getString("username")); listeConcept.add(c); } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting historique of Concept : " + idConcept, sqle); } return listeConcept; }
From source file:org.apache.marmotta.kiwi.persistence.KiWiConnection.java
/** * Construct a batch of KiWiTriples from the result of an SQL query. This query differs from constructTripleFromDatabase * in that it does a batch-prefetching for optimized performance * * @param row a database result containing the columns described above * @return a KiWiTriple representation of the database result *///from www . j a va 2 s . c om protected List<KiWiTriple> constructTriplesFromDatabase(ResultSet row, int maxPrefetch) throws SQLException { int count = 0; // declare variables to optimize stack allocation KiWiTriple triple; long id; List<KiWiTriple> result = new ArrayList<>(); Map<Long, Long[]> tripleIds = new HashMap<>(); Set<Long> nodeIds = new HashSet<>(); while (count < maxPrefetch && row.next()) { count++; if (row.isClosed()) { throw new ResultInterruptedException("retrieving results has been interrupted"); } // columns: id,subject,predicate,object,context,deleted,inferred,creator,createdAt,deletedAt // 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 id = row.getLong(1); triple = tripleCache.get(id); // lookup element in cache first, so we can avoid reconstructing it if it is already there if (triple != null) { result.add(triple); } else { triple = new KiWiTriple(); triple.setId(id); // collect node ids for batch retrieval nodeIds.add(row.getLong(2)); nodeIds.add(row.getLong(3)); nodeIds.add(row.getLong(4)); if (row.getLong(5) != 0) { nodeIds.add(row.getLong(5)); } if (row.getLong(8) != 0) { nodeIds.add(row.getLong(8)); } // remember which node ids where relevant for the triple tripleIds.put(id, new Long[] { row.getLong(2), row.getLong(3), row.getLong(4), row.getLong(5), row.getLong(8) }); triple.setDeleted(row.getBoolean(6)); triple.setInferred(row.getBoolean(7)); triple.setCreated(new Date(row.getTimestamp(9).getTime())); try { if (row.getDate(10) != null) { triple.setDeletedAt(new Date(row.getTimestamp(10).getTime())); } } catch (SQLException ex) { // work around a MySQL problem with null dates // (see http://stackoverflow.com/questions/782823/handling-datetime-values-0000-00-00-000000-in-jdbc) } result.add(triple); } } KiWiNode[] nodes = loadNodesByIds(Longs.toArray(nodeIds)); Map<Long, KiWiNode> nodeMap = new HashMap<>(); for (int i = 0; i < nodes.length; i++) { nodeMap.put(nodes[i].getId(), nodes[i]); } for (KiWiTriple t : result) { if (tripleIds.containsKey(t.getId())) { // need to set subject, predicate, object, context and creator Long[] ids = tripleIds.get(t.getId()); t.setSubject((KiWiResource) nodeMap.get(ids[0])); t.setPredicate((KiWiUriResource) nodeMap.get(ids[1])); t.setObject(nodeMap.get(ids[2])); if (ids[3] != 0) { t.setContext((KiWiResource) nodeMap.get(ids[3])); } if (ids[4] != 0) { t.setCreator((KiWiResource) nodeMap.get(ids[4])); } } cacheTriple(t); } return result; }
From source file:mom.trd.opentheso.bdd.helper.ConceptHelper.java
/** * Cette fonction permet de rcuprer l'historique d'un concept une date * prcise//ww w. j av a2 s . c o m * * @param ds * @param idConcept * @param idThesaurus * @param date * @return String idGroup */ public ArrayList<Concept> getConceptHisoriqueFromDate(HikariDataSource ds, String idConcept, String idThesaurus, java.util.Date date) { ArrayList<Concept> listeConcept = new ArrayList<>(); Connection conn; Statement stmt; ResultSet resultSet; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT modified, status, notation, top_concept, id_group, username from concept_historique, users where id_thesaurus = '" + idThesaurus + "'" + " and id_concept = '" + idConcept + "'" + " and concept_historique.id_user=users.id_user" + " and modified <= '" + date + "' order by modified DESC"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { while (resultSet.next()) { Concept c = new Concept(); c.setIdConcept(idConcept); c.setIdThesaurus(idThesaurus); c.setModified(resultSet.getDate("modified")); c.setStatus(resultSet.getString("status")); c.setNotation(resultSet.getString("notation")); c.setTopConcept(resultSet.getBoolean("top_concept")); c.setIdGroup(resultSet.getString("id_group")); c.setUserName(resultSet.getString("username")); listeConcept.add(c); } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting date historique of Concept : " + idConcept, sqle); } return listeConcept; }
From source file:ProcessRequest.java
public JSONArray parseQueryResults(ResultSet rs, String table) throws SQLException, JSONException { JSONArray resultJSONArray = new JSONArray(); ResultSetMetaData rsmd = rs.getMetaData(); int columns = rsmd.getColumnCount(); while (rs.next()) { JSONObject result = new JSONObject(); JSONObject resultMeta = new JSONObject(); resultMeta.put("table", table); result.put("metadata", resultMeta); for (int i = 1; i <= columns; i++) { //out.println("<td>"+rs.getString(i)+"</td>"); int type = rsmd.getColumnType(i); //result.put(rsmd.getColumnName(i), rs.get) switch (type) { case Types.BIT: result.put(rsmd.getColumnName(i), rs.getBoolean(i)); break; case Types.TINYINT: result.put(rsmd.getColumnName(i), rs.getInt(i)); break; case Types.SMALLINT: result.put(rsmd.getColumnName(i), rs.getInt(i)); break; case Types.INTEGER: //System.out.println(rsmd.getColumnName(i) + " type: "+type); result.put(rsmd.getColumnName(i), rs.getInt(i)); break; case Types.BIGINT: result.put(rsmd.getColumnName(i), rs.getInt(i)); break; case Types.FLOAT: result.put(rsmd.getColumnName(i), rs.getFloat(i)); break; case Types.REAL: result.put(rsmd.getColumnName(i), rs.getDouble(i)); break; case Types.DOUBLE: result.put(rsmd.getColumnName(i), rs.getDouble(i)); break; case Types.NUMERIC: result.put(rsmd.getColumnName(i), rs.getDouble(i)); break; case Types.DECIMAL: result.put(rsmd.getColumnName(i), rs.getDouble(i)); break; case Types.CHAR: result.put(rsmd.getColumnName(i), rs.getString(i)); break; case Types.VARCHAR: result.put(rsmd.getColumnName(i), rs.getString(i)); break; case Types.LONGVARCHAR: result.put(rsmd.getColumnName(i), rs.getString(i)); break; case Types.DATE: { java.util.Date date = rs.getDate(i); result.put(rsmd.getColumnName(i), date.getTime()); break; }/* w w w . j av a 2 s . co m*/ case Types.TIME: { java.util.Date date = rs.getDate(i); result.put(rsmd.getColumnName(i), date.getTime()); break; } case Types.TIMESTAMP: { java.util.Date date = rs.getDate(i); result.put(rsmd.getColumnName(i), date.getTime()); break; } case Types.BINARY: result.put(rsmd.getColumnName(i), rs.getInt(i)); break; case Types.VARBINARY: result.put(rsmd.getColumnName(i), rs.getInt(i)); break; case Types.LONGVARBINARY: result.put(rsmd.getColumnName(i), rs.getLong(i)); break; case Types.NULL: result.put(rsmd.getColumnName(i), ""); break; case Types.BOOLEAN: result.put(rsmd.getColumnName(i), rs.getBoolean(i)); break; case Types.ROWID: result.put(rsmd.getColumnName(i), rs.getInt(i)); break; case Types.NCHAR: result.put(rsmd.getColumnName(i), rs.getString(i)); break; case Types.NVARCHAR: result.put(rsmd.getColumnName(i), rs.getString(i)); break; case Types.LONGNVARCHAR: result.put(rsmd.getColumnName(i), rs.getString(i)); break; case Types.SQLXML: case Types.NCLOB: case Types.DATALINK: case Types.REF: case Types.OTHER: case Types.JAVA_OBJECT: case Types.DISTINCT: case Types.STRUCT: case Types.ARRAY: case Types.BLOB: case Types.CLOB: default: result.put(rsmd.getColumnName(i), rs.getString(i)); break; } } //if(table.equals("Ticket")) //System.out.println(result.toString(5)); resultJSONArray.put(result); } return resultJSONArray; }
From source file:interfazGrafica.loginInterface.java
private void venderBuscarCotButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_venderBuscarCotButtonActionPerformed // TODO add your handling code here: String codigoCotizacion = codCotVender.getText(); ResultSet consulta = new Venta().buscarCotizacion(codigoCotizacion); try {/*from w ww.j a v a 2s .c o m*/ while (consulta.next()) { Date fechaCotizacion = consulta.getDate("fecha_cotizacion"); Date fechaVencimiento = new Cotizaciones().obtenerFechaVencimiento(fechaCotizacion); Date fechaActual = new Date(); if (fechaActual.after(fechaCotizacion) && fechaActual.before(fechaVencimiento)) { codCotVender.setText(codigoCotizacion); codVendedorVender.setText(consulta.getString("id_usuario")); codCompradorVender.setText(consulta.getString("id_comprador")); codVehiculoVender.setText(consulta.getString("id_vehiculo")); } else { JOptionPane.showMessageDialog(null, "La cotizacin ha expirado", "Error", JOptionPane.ERROR_MESSAGE); } } } catch (SQLException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "Error", "Eror", JOptionPane.ERROR_MESSAGE); } }