List of usage examples for java.sql Date valueOf
@SuppressWarnings("deprecation") public static Date valueOf(LocalDate date)
From source file:com.plat4u.ghost.common.util.DateConverter.java
public <T> T convert(Class<T> type, Object value) { if (value == null) { // (java.sql.Date)null return (T) (java.sql.Date) null; } else {//ww w .j av a2s . c o m if (value instanceof java.lang.String) { return (T) Date.valueOf((String) value); } return (T) (java.sql.Date) null; } }
From source file:org.yukung.tasklet.utils.DateConverter.java
@SuppressWarnings("unchecked") @Override/*from www. j a va2s .c o m*/ public Object convert(Class type, Object value) { if (value.toString().equals("")) { return null; } else { return Date.valueOf(value.toString().replace("/", "-")); } }
From source file:com.seguriboxltv.core.dao.impl.AuditTrailDaoImpl.java
@Override public List<AuditTrail> Get(Date eventDate, byte CategoryCode, int EventCode, short pageNumber, short pages, int rows) throws Exception { sql = "{call AuditTrailGet(?,?,?,?,?,?,?)}"; List<AuditTrail> list = new ArrayList<>(); try {//from ww w.j a v a 2s . c om conn = dataSource.getConnection(); cstmt = conn.prepareCall(sql); cstmt.setDate("EventDate", Date.valueOf("2016-11-04")); cstmt.setByte("CategoryCode", CategoryCode); cstmt.setInt("EventCode", EventCode); cstmt.setShort("PageSize", pages); rsl = cstmt.executeQuery(); while (rsl.next()) { AuditTrail auditTrail = new AuditTrail(); auditTrail.setEventDate(rsl.getDate("EventDate")); auditTrail.setEventCode(rsl.getShort("EventCode")); auditTrail.setUserHostIp(rsl.getString("UserHostIP")); auditTrail.setFullUserName(rsl.getString("FullNameUser")); auditTrail.setObjectName(rsl.getString("ObjectName")); auditTrail.setObjectId(rsl.getInt("ObjectId")); auditTrail.setInstanceName(rsl.getString("InstanceName")); auditTrail.setNotes(rsl.getString("Notes")); list.add(auditTrail); } } catch (SQLException e) { throw e; } catch (Exception e) { throw e; } return list; }
From source file:org.beangle.commons.converters.SqlDateConverter.java
/** * ??<br>//from w w w . ja v a 2s. c om * format 1: yyyy-MM-dd<br> * format 2: yyyyMMdd * * @param type * @param value * @return */ protected Object convertToDate(final Object value) { if (value instanceof String) { if (StringUtils.isEmpty((String) value)) { return null; } else { String dateStr = (String) value; if (!StringUtils.contains(dateStr, "-")) { StringBuilder dateBuf = new StringBuilder(dateStr); dateBuf.insert("yyyyMM".length(), '-'); dateBuf.insert("yyyy".length(), '-'); dateStr = dateBuf.toString(); } return Date.valueOf(dateStr); } } else if (value instanceof java.util.Date) { return new Date(((java.util.Date) value).getTime()); } else { return null; } }
From source file:com.ebay.nest.io.sede.lazy.LazyDate.java
/** * Initializes LazyDate object by interpreting the input bytes as a SQL date string. * * @param bytes//from w w w . java 2 s . co m * @param start * @param length */ @Override public void init(ByteArrayRef bytes, int start, int length) { String s = null; try { s = Text.decode(bytes.getData(), start, length); data.set(Date.valueOf(s)); isNull = false; } catch (Exception e) { isNull = true; logExceptionMessage(bytes, start, length, "DATE"); } }
From source file:svc.data.citations.datasources.mock.MockCitationDataSource.java
@Override public List<Citation> getByLicenseAndDOB(String driversLicenseNumber, String driversLicenseState, LocalDate dob) {/*from ww w . j a v a 2s . com*/ try { Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("driversLicenseNumber", driversLicenseNumber); parameterMap.put("driversLicenseState", driversLicenseState); parameterMap.put("dob", Date.valueOf(dob)); String sql = "SELECT * FROM citations WHERE date_of_birth = :dob AND drivers_license_number = :driversLicenseNumber AND drivers_license_state = :driversLicenseState"; List<Citation> citations = jdbcTemplate.query(sql, parameterMap, new CitationSQLMapper()); return populateViolations(citations); } catch (Exception e) { LogSystem.LogDBException(e); return null; } }
From source file:com.create.batch.TicketReaderFactoryTest.java
@Test public void testCreateReaderAndReadCorrectData() throws Exception { // given//from ww w. j a va 2 s . c o m final ExecutionContext executionContext = mock(ExecutionContext.class); final LocalDate date = LocalDate.of(2015, 12, 20); // when final ItemStreamReader<Ticket> reader = factory.createReader(new ClassPathResource("tickets.csv")); final Ticket ticket; try { reader.open(executionContext); ticket = reader.read(); } finally { reader.close(); } // then assertThat(ticket, notNullValue()); assertThat(ticket.getTag(), equalTo("Ticket_0")); assertThat(ticket.getDate(), equalTo(Date.valueOf(date))); assertThat(ticket.getContent(), equalTo("Test ticket")); }
From source file:org.apache.ddlutils.platform.DefaultValueHelper.java
/** * Converts the given default value from the specified original to the target * jdbc type./* w w w .j av a 2 s . c o m*/ * * @param defaultValue The default value * @param originalTypeCode The original type code * @param targetTypeCode The target type code * @return The converted default value */ public String convert(String defaultValue, int originalTypeCode, int targetTypeCode) { String result = defaultValue; if (defaultValue != null) { switch (originalTypeCode) { case Types.BIT: case Types.BOOLEAN: result = convertBoolean(defaultValue, targetTypeCode).toString(); break; case Types.DATE: if (targetTypeCode == Types.TIMESTAMP) { try { Date date = Date.valueOf(result); return new Timestamp(date.getTime()).toString(); } catch (IllegalArgumentException ex) { } } break; case Types.TIME: if (targetTypeCode == Types.TIMESTAMP) { try { Time time = Time.valueOf(result); return new Timestamp(time.getTime()).toString(); } catch (IllegalArgumentException ex) { } } break; } } return result; }
From source file:cz.fi.muni.pa165.service.layer.service.AlbumServiceImplementationTest.java
@BeforeClass public void setUp() { MockitoAnnotations.initMocks(this); Genre rock = new Genre(); rock.setTitle("Hard Rock"); rock.setYearOfOrigin(1950);/*from ww w .ja v a 2 s.c o m*/ direStraits = new Musician(); direStraits.setRealName("Mark Knopfler"); direStraits.setArtistName("Dire Straits"); direStraits.setDateOfBirth(Date.valueOf("1949-12-8")); brothersInArmsAlbum = new Album(); brothersInArmsAlbum.setMusician(direStraits); brothersInArmsAlbum.setReleaseDate(Date.valueOf("1985-6-13")); brothersInArmsAlbum.setTitle("Brothers in Arms"); onEveryStreetAlbum = new Album(); onEveryStreetAlbum.setMusician(direStraits); onEveryStreetAlbum.setReleaseDate(Date.valueOf("1991-10-11")); onEveryStreetAlbum.setTitle("On Every Street"); shootToThrillSong = new Song(); shootToThrillSong.setTitle("Shoot To Thrill"); shootToThrillSong.setAlbum(brothersInArmsAlbum); shootToThrillSong.setGenre(rock); shootToThrillSong.setMusician(direStraits); shootToThrillSong.setAlbumPosition(2); shootToThrillSong.setBitrate(320); moneyForNothingSong = new Song(); moneyForNothingSong.setTitle("Money For Nothing"); moneyForNothingSong.setAlbum(brothersInArmsAlbum); moneyForNothingSong.setGenre(rock); moneyForNothingSong.setMusician(direStraits); moneyForNothingSong.setAlbumPosition(2); moneyForNothingSong.setBitrate(320); }
From source file:cz.fi.muni.pa165.service.layer.facade.AlbumFacadeImplementationTest.java
@BeforeClass public void setUp() { MockitoAnnotations.initMocks(this); acdc = new Musician(); acdc.setRealName("Brian Johnson"); acdc.setArtistName("AC/DC"); acdc.setDateOfBirth(Date.valueOf("1945-10-15")); backInBlackAlbum = new Album(); backInBlackAlbum.setMusician(acdc);/*from w ww . j a v a 2 s.c o m*/ backInBlackAlbum.setReleaseDate(Date.valueOf("1980-7-25")); backInBlackAlbum.setTitle("Back In Black"); shootToThrillSong = new Song(); shootToThrillSong.setTitle("Shoot To Thrill"); shootToThrillSong.setAlbum(backInBlackAlbum); shootToThrillSong.setGenre(progressiveRock); shootToThrillSong.setMusician(acdc); shootToThrillSong.setAlbumPosition(2); shootToThrillSong.setBitrate(320); albumDTO = new AlbumDTO(); albumDTO.setTitle(backInBlackAlbum.getTitle()); albumDTO.setReleaseDate(backInBlackAlbum.getReleaseDate()); albumDTO.setMusician(new MusicianDTO()); albumDTO.setCover(backInBlackAlbum.getCover()); progressiveRock = new Genre(); progressiveRock.setTitle("Progressive Rock"); progressiveRock.setYearOfOrigin(1960); }