List of usage examples for java.sql ResultSet getTimestamp
java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Timestamp
object in the Java programming language. From source file:fr.aliacom.obm.common.calendar.CalendarDaoJdbcImpl.java
@VisibleForTesting Event eventFromCursor(Calendar cal, ResultSet evrs) throws SQLException { Event e = new Event(); int id = evrs.getInt("event_id"); e.setUid(new EventObmId(id)); e.setEntityId(EntityId.valueOf(evrs.getInt("evententity_entity_id"))); e.setTimeUpdate(JDBCUtils.getDate(evrs, "event_timeupdate")); e.setTimeCreate(JDBCUtils.getDate(evrs, "event_timecreate")); e.setTimezoneName(evrs.getString("event_timezone")); e.setType(EventType.valueOf(evrs.getString("event_type"))); e.setExtId(new EventExtId(evrs.getString("event_ext_id"))); e.setOpacity(EventOpacity.getValueOf(evrs.getString("event_opacity"))); e.setCategory(evrs.getString("eventcategory1_label")); e.setTitle(evrs.getString("event_title")); e.setLocation(evrs.getString("event_location")); cal.setTimeInMillis(evrs.getTimestamp("event_date").getTime()); e.setStartDate(cal.getTime());/*from ww w. j ava 2s . c om*/ e.setDuration(JDBCUtils.convertNegativeIntegerToZero(evrs, "event_duration")); e.setPriority(evrs.getInt("event_priority")); e.setPrivacy(EventPrivacy.valueOf(evrs.getInt("event_privacy"))); e.setAllday(evrs.getBoolean("event_allday")); e.setDescription(evrs.getString("event_description")); e.setSequence(evrs.getInt("event_sequence")); e.setRecurrence(eventRecurrenceFromCursor(cal, evrs)); String domainName = evrs.getString("domain_name"); e.setOwner(evrs.getString("owner")); e.setOwnerEmail(getUserObmEmail(evrs, domainName)); e.setOwnerDisplayName(getOwnerDisplayName(evrs)); e.setCreatorEmail(getCreatorObmEmail(evrs, domainName)); e.setCreatorDisplayName(getCreatorDisplayName(evrs)); Timestamp recurrenceId = evrs.getTimestamp("recurrence_id"); if (recurrenceId != null) { cal.setTimeInMillis(recurrenceId.getTime()); e.setRecurrenceId(cal.getTime()); } return e; }
From source file:ca.sqlpower.matchmaker.address.AddressPool.java
public void load(Logger engineLogger) throws SQLException, SQLObjectException { setCancelled(false);/*from w ww . j a v a 2 s. com*/ setStarted(true); setFinished(false); setProgress(0); SQLTable resultTable = project.getResultTable(); Connection con = null; Statement stmt = null; ResultSet rs = null; setJobSize(getNumRowsToProcess()); try { con = project.createResultTableConnection(); stmt = con.createStatement(); StringBuilder sql = new StringBuilder("SELECT * FROM "); appendFullyQualifiedTableName(sql, resultTable); rs = stmt.executeQuery(sql.toString()); while (rs.next()) { List<Object> keyValues = new ArrayList<Object>(); int numKeys = project.getSourceTableIndex().getChildCount(); // We need to convert the column types to the base set of // String, Boolean, BigDecimal, and Date that we use in the // Transformations. Otherwise, when we cannot properly compare // the key values of these loaded. Addresses with the ones // coming through the transformations. for (int i = 0; i < numKeys; i++) { int type = project.getSourceTableIndex().getChild(i).getColumn().getType(); Class c = TypeMap.typeClass(type); if (c == BigDecimal.class) { keyValues.add(rs.getBigDecimal(SOURCE_ADDRESS_KEY_COLUMN_BASE + i)); } else if (c == Date.class) { /* * KLUDGE. DateTime types are converted to Date's, thus losing * the Time portion of the value. When paging through results * and a DateTime column is used as part of the key, then inconsistent * paging will occur as the comparison logic will be comparing just * Date values. To avoid breaking any other parts of the application * as it is only the paging that is affected by this change, * explicitly check for the Timestamp type, and retrieve the right * type from the ResultSet here, instead of altering TypeMap.typeClass(). */ if (type == Types.TIMESTAMP) { keyValues.add(rs.getTimestamp(SOURCE_ADDRESS_KEY_COLUMN_BASE + i)); } else { keyValues.add(rs.getDate(SOURCE_ADDRESS_KEY_COLUMN_BASE + i)); } } else if (c == Boolean.class) { keyValues.add(rs.getBoolean(SOURCE_ADDRESS_KEY_COLUMN_BASE + i)); } else { keyValues.add(rs.getString(SOURCE_ADDRESS_KEY_COLUMN_BASE + i)); } } String addressLine1 = rs.getString(INPUT_ADDRESS_LINE1); String addressLine2 = rs.getString(INPUT_ADDRESS_LINE2); String municipality = rs.getString(INPUT_MUNICIPALITY); String province = rs.getString(INPUT_PROVINCE); String country = rs.getString(INPUT_COUNTRY); String postalCode = rs.getString(INPUT_POSTAL_CODE); Address address = new Address(); address.setCountry(rs.getString(OUTPUT_COUNTRY)); String deliveryInstallName; try { deliveryInstallName = rs.getString(OUTPUT_DELIVERY_INSTALLATION_NAME); } catch (SQLException e) { deliveryInstallName = rs.getString(OLD_OUTPUT_DELIVERY_INSTALLATION_NAME); } address.setDeliveryInstallationName(deliveryInstallName); String deliveryInstallType; try { deliveryInstallType = rs.getString(OUTPUT_DELIVERY_INSTALLATION_TYPE); } catch (SQLException e) { deliveryInstallType = rs.getString(OLD_OUTPUT_DELIVERY_INSTALLATION_TYPE); } address.setDeliveryInstallationType(deliveryInstallType); address.setDirectionPrefix(rs.getBoolean(OUTPUT_DIRECTION_PREFIX)); address.setFailedParsingString(rs.getString(OUTPUT_FAILED_PARSING_STRING)); address.setGeneralDeliveryName(rs.getString(OUTPUT_GENERAL_DELIVERY_NAME)); address.setLockBoxNumber(rs.getString(OUTPUT_LOCK_BOX_NUMBER)); address.setLockBoxType(rs.getString(OUTPUT_LOCK_BOX_TYPE)); address.setMunicipality(rs.getString(OUTPUT_MUNICIPALITY)); address.setPostalCode(rs.getString(OUTPUT_POSTAL_CODE)); address.setProvince(rs.getString(OUTPUT_PROVINCE)); address.setRuralRouteNumber(rs.getString(OUTPUT_RURAL_ROUTE_NUMBER)); address.setRuralRouteType(rs.getString(OUTPUT_RURAL_ROUTE_TYPE)); address.setStreet(rs.getString(OUTPUT_STREET_NAME)); address.setStreetDirection(rs.getString(OUTPUT_STREET_DIRECTION)); address.setStreetNumberSuffix(rs.getString(OUTPUT_STREET_NUMBER_SUFFIX)); String streetNumSuffix; try { streetNumSuffix = rs.getString(OUTPUT_STREET_NUMBER_SUFFIX_SEPARATE); } catch (SQLException e) { streetNumSuffix = rs.getString(OLD_OUTPUT_STREET_NUMBER_SUFFIX_SEPARATE); } address.setStreetNumberSuffix(streetNumSuffix); address.setStreetNumber(rs.getInt(OUTPUT_STREET_NUMBER)); address.setStreetType(rs.getString(OUTPUT_STREET_TYPE)); address.setStreetTypePrefix(rs.getBoolean(OUTPUT_STREET_TYPE_PREFIX)); address.setSuite(rs.getString(OUTPUT_SUITE)); address.setSuitePrefix(rs.getBoolean(OUTPUT_SUITE_PREFIX)); address.setSuiteType(rs.getString(OUTPUT_SUITE_TYPE)); String typeString = rs.getString(OUTPUT_TYPE); if (typeString != null) { address.setType(RecordType.valueOf(rs.getString(OUTPUT_TYPE))); } address.setUnparsedAddressLine1(rs.getString(OUTPUT_UNPARSED_ADDRESS)); address.setUrbanBeforeRural(rs.getBoolean(OUTPUT_URBAN_BEFORE_RURAL)); Boolean valid = rs.getBoolean(OUTPUT_VALID); AddressResult result = new AddressResult(keyValues, addressLine1, addressLine2, municipality, province, postalCode, country, address, valid); result.markClean(); addresses.put(keyValues, result); incrementProgress(); } engineLogger.debug("Loaded " + addresses.size() + " addresses from the result table"); } finally { setFinished(true); if (rs != null) rs.close(); if (stmt != null) stmt.close(); if (con != null) con.close(); } }
From source file:com.uas.document.DocumentDAO.java
@Override public ArrayList<DocumentDTO> getDocumentsByUser(UsuarioDTO dto) { kFac = new KeywordFacade(); ArrayList<DocumentDTO> documents = null; DocumentDTO document = null;//from w w w.j av a 2 s . co m ResultSet rs = null; Connection c = null; PreparedStatement ps = null; documents = new ArrayList<DocumentDTO>(); try { c = DataSourceSingleton.getInstance().getConnection(); String SQL = "SELECT \"object\".\"id\",\"object\".\"createdBy\", \"object\".\"name\", \"object\".\"description\", \"object\".\"createdOn\", \"object\".\"createdBy\", \"object\".\"color\", \"object\".\"kind\", \"document\".\"fileName\", \"document\".\"isFolder\", \"document\".\"deleted\", \"document\".\"fileDate\", \"document\".\"idArea\", \"object3\".\"name\" AS \"nameArea\", \"object2\".\"name\" AS \"nameCreatedBy\" FROM \"document\" JOIN \"object\" ON \"document\".\"id\" = \"object\".\"id\" JOIN \"object\" AS \"object3\" ON \"document\".\"idArea\" = \"object3\".\"id\" JOIN \"object\" AS \"object2\" ON \"object\".\"createdBy\" = \"object2\".\"id\" where \"object\".\"createdBy\" = ? ORDER BY \"object\".\"createdOn\" ASC"; ps = c.prepareStatement(SQL); ps.setInt(1, dto.getId()); rs = ps.executeQuery(); while (rs.next()) { document = new DocumentDTO(); document.setId(rs.getInt("id")); document.setCreatedBy(rs.getInt("createdBy")); document.setIsFolder(rs.getBoolean("isFolder")); document.setName(rs.getString("name")); document.setDescription(rs.getString("description")); document.setColor(rs.getString("color")); document.setDeleted(rs.getBoolean("deleted")); document.setCreatedOn(rs.getTimestamp("createdOn")); document.setKind(rs.getString("kind")); document.setFilename(rs.getString("filename")); document.setKeywords(kFac.getKeywordsByDocument(document)); document.setFileDate(rs.getString("fileDate")); document.setIdArea(rs.getInt("idArea")); document.getArea().setName(rs.getString("nameArea")); document.getUser().setName(rs.getString("nameCreatedBy")); documents.add(document); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (rs != null) { rs.close(); } if (c != null) { c.close(); } if (ps != null) { ps.close(); } } catch (Exception e2) { e2.printStackTrace(); } } return documents; }