Example usage for java.sql Time valueOf

List of usage examples for java.sql Time valueOf

Introduction

In this page you can find the example usage for java.sql Time valueOf.

Prototype

@SuppressWarnings("deprecation")
public static Time valueOf(LocalTime time) 

Source Link

Document

Obtains an instance of Time from a LocalTime object with the same hour, minute and second time value as the given LocalTime .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Time time = new Time(0);

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    String sql = "INSERT child VALUES(?,?)";
    PreparedStatement prest = con.prepareStatement(sql);
    prest.setString(1, "vinod");
    prest.setTime(2, time.valueOf("1:60:60"));
    int row = prest.executeUpdate();
    System.out.println(row + " row(s) affectec)");
}

From source file:Main.java

public static void main(String[] args) {
    Calendar someTime = Calendar.getInstance();
    someTime.set(Calendar.HOUR_OF_DAY, 17);
    someTime.set(Calendar.MINUTE, 0);
    someTime.set(Calendar.SECOND, 0);

    // convert it to java epoch date
    Date someDate = toEpochDate(someTime);

    // create a date object from java.sql.Time
    Date fromSqlTime = new Date(Time.valueOf("17:00:00").getTime());

    // now do the comparison
    System.out.println("Some Date: " + someDate.toString());
    System.out.println("Sql Time: " + fromSqlTime.toString());
    System.out.println("Are they equal? " + someDate.equals(fromSqlTime));
}

From source file:Main.java

/**
 * Method to convert a calendar object to java's epoch date keeping only the
 * time information/*from  w  ww .  ja  va2s .  c  o m*/
 */
public static Date toEpochDate(Calendar calendar) {
    return new Date(Time.valueOf(new SimpleDateFormat("HH:mm:ss").format(calendar.getTime())).getTime());
}

From source file:bq.jpa.demo.datetype.service.EmployeeService.java

@Transactional
public Employee create() {
    Employee employee = new Employee();

    employee.setEmployeeName("bq");
    employee.setGender('m');
    employee.setFamilymember((short) 5);
    employee.setOnline(false);//from  ww w  . j  a v  a2  s . co m
    employee.setRetired(false);
    employee.setSalary(10000);
    employee.setSaleAmount(new BigDecimal("10000000"));

    Calendar date = Calendar.getInstance();
    date.set(1980, 8, 18);
    employee.setBirthday(date.getTime());

    employee.setLastLoginTime(new Timestamp(System.currentTimeMillis()));
    employee.setTimeFrom(Time.valueOf("08:30:00"));

    employee.setType(EmployeeType.FULL_TIME_EMPLOYEE);

    Address homeAddress = new Address();
    homeAddress.setNumber("88");
    homeAddress.setRoad("Rich");
    homeAddress.setCity("New York");
    homeAddress.setState("NY");
    homeAddress.setCountry("USA");
    employee.setHomeAddress(homeAddress);

    //read png file
    try {
        employee.setPicture(readImage("/datetype/picture.png"));
    } catch (IOException e) {
        e.printStackTrace();
        employee.setPicture(null);
    }

    // read txt file
    try {
        employee.setResume(readFile("/datetype/resume.txt"));
    } catch (IOException | URISyntaxException e) {
        e.printStackTrace();
        employee.setResume(null);
    }

    em.persist(employee);
    return employee;
}

From source file:org.motechproject.server.omod.web.controller.MotechModuleFormControllerTest.java

public void testViewBlackoutForm() throws ParseException {

    Time startTime = Time.valueOf("07:00:00"), endTime = Time.valueOf("19:00:00");

    Blackout interval = new Blackout(startTime, endTime);
    expect(contextService.getMotechService()).andReturn(motechService);
    expect(motechService.getBlackoutSettings()).andReturn(interval);

    replay(contextService, motechService);

    ModelMap model = new ModelMap();
    String path = controller.viewBlackoutSettings(model);

    verify(contextService, motechService);

    assertEquals("/module/motechmodule/blackout", path);
    assertEquals(model.get("startTime"), startTime);
    assertEquals(model.get("endTime"), endTime);
}

From source file:com.sg.superbeingsightings.dao.SightingDaoTest.java

/**
 * Test of addSighting, getSighting and removeSighting method, of class SightingDao.
 *///from  ww  w.j a  v a2 s .  co m
@Test
public void testAddGetRemoveSighting() {
    Address address = new Address();
    address.setStreet("401 S Main St");
    address.setCity("Akron");
    address.setState("OH");
    address.setZip("12345");

    addressDao.addAddress(address);

    Location location = new Location();
    location.setAddress(address);
    location.setName("401 Loft");
    location.setDesc("Its Lovely.");
    location.setLatitude(new BigDecimal("-23.2347"));
    location.setLongitude(new BigDecimal("123.1234"));

    locationDao.addLocation(location);

    Sighting sighting = new Sighting();
    sighting.setLocation(location);
    sighting.setDate(java.sql.Date.valueOf("2017-3-27"));
    sighting.setTime(Time.valueOf("13:37:00"));
    sighting.setDesc("Plastic bag floated in the wind.");

    sightingDao.addSighting(sighting);

    Sighting sightingFromDao = sightingDao.getSighting(sighting.getSightingID());
    Location locationFromDao = locationDao.getLocation(location.getLocationID());
    Address addressFromDao = addressDao.getAddress(locationFromDao.getAddress().getAddressID());
    locationFromDao.setAddress(addressFromDao);
    sightingFromDao.setLocation(locationFromDao);
    assertTrue(sightingFromDao.equals(sighting));
}

From source file:com.ebay.erl.mobius.core.model.TupleTest.java

@Test
public void test_comparator() {
    Tuple t1 = new Tuple();
    Tuple t2 = new Tuple();

    // comparing short
    t1.put("C1", (byte) 12);
    t2.put("C1", (byte) 10);
    assertTrue(t1.compareTo(t2) > 0);
    assertTrue(t2.compareTo(t1) < 0);

    // comparing short
    t1.put("C1", (short) 12);
    t2.put("C1", (short) 10);
    assertTrue(t1.compareTo(t2) > 0);
    assertTrue(t2.compareTo(t1) < 0);

    // comparing integer
    t1.put("C1", (int) 10);
    t2.put("C1", (int) 10);
    assertTrue(t1.compareTo(t2) == 0);//  w w  w.j a  va 2s  .co m
    assertFalse(t2.compareTo(t1) < 0);
    assertFalse(t1.compareTo(t2) > 0);

    // comparing long
    t1.put("C1", 200000000L);
    t2.put("C1", 300000000L);
    assertTrue(t1.compareTo(t2) != 0);
    assertFalse(t1.compareTo(t2) > 0);
    assertTrue(t1.compareTo(t2) < 0);

    // comparing float
    t1.put("C1", 1.2F);
    t2.put("C1", 1.1F);
    assertTrue(t1.compareTo(t2) > 0);
    assertTrue(t2.compareTo(t1) < 0);

    // comparing double
    t1.put("C1", 1.7D);
    t2.put("C1", 1.5D);
    assertTrue(t1.compareTo(t2) > 0);
    assertTrue(t2.compareTo(t1) < 0);

    // comparing string
    t1.put("C1", "AA");
    t2.put("C1", "AB");
    assertTrue(t1.compareTo(t2) < 0);
    assertTrue(t2.compareTo(t1) > 0);

    // comparing date
    t1.put("C1", java.sql.Date.valueOf("2011-01-01"));
    t2.put("C1", java.sql.Date.valueOf("2011-01-02"));
    assertTrue(t1.compareTo(t2) < 0);
    assertTrue(t2.compareTo(t1) > 0);

    // comparing Timestamp
    Timestamp ts1 = Timestamp.valueOf("2011-12-31 12:30:42");
    Timestamp ts2 = Timestamp.valueOf("2011-12-31 12:30:12");
    t1.put("C1", ts1);
    t2.put("C1", ts2);
    assertTrue(t1.compareTo(t2) > 0);
    assertTrue(t2.compareTo(t1) < 0);

    // comparing Time
    Time tt1 = Time.valueOf("12:30:42");
    Time tt2 = Time.valueOf("12:30:12");
    t1.put("C1", tt1);
    t2.put("C1", tt2);
    assertTrue(t1.compareTo(t2) > 0);
    assertTrue(t2.compareTo(t1) < 0);

    // comparing boolean
    t1.put("C1", true);
    t2.put("C1", false);
    assertTrue(t1.compareTo(t2) > 0);
    assertTrue(t2.compareTo(t1) < 0);

    // comparing string map
    CaseInsensitiveTreeMap m1 = new CaseInsensitiveTreeMap();
    CaseInsensitiveTreeMap m2 = new CaseInsensitiveTreeMap();
    t1.put("C1", m1);
    t2.put("C1", m2);
    assertTrue(t1.compareTo(t2) == 0);

    m1.put("K1", "V1");
    assertTrue(t1.compareTo(t2) > 0); // m1 is not empty, m2 is empty

    m2.put("K1", "V1");
    assertTrue(t1.compareTo(t2) == 0);// m1 and m2 both are not empty and same value

    m1.put("K1", "V2");
    assertTrue(t1.compareTo(t2) > 0);// m1 m2 has same key but different value

    m1.put("K1", "V1");
    m1.put("K2", "V2");
    assertTrue(t1.compareTo(t2) > 0);// m1 m2 both has same K1 and V1, but m1 has more k-v pair
    assertTrue(t2.compareTo(t1) < 0);

    // comparing WritableComparable
    t1.put("C1", new Text("AC"));
    t2.put("C1", new Text("AA"));
    assertTrue(t1.compareTo(t2) > 0);
    assertTrue(t2.compareTo(t1) < 0);

    // comparing serializable type
    t1.put("C1", new BigDecimal(123L));
    t2.put("C1", new BigDecimal(456L));
    assertTrue(t1.compareTo(t2) < 0);
    assertTrue(t2.compareTo(t1) > 0);

    // comparing null type
    t1.put("C1", this.getNull());
    t2.put("C1", new BigDecimal(456L));

    assertTrue(t1.compareTo(t2) < 0);
    assertTrue(t2.compareTo(t1) > 0);

    t2.put("C1", this.getNull());
    assertTrue(t1.compareTo(t2) == 0);

    // comparing different numerical type
    t1.put("C1", 1.2F);
    t2.put("C1", 1);
    assertTrue(t1.compareTo(t2) > 0);
}

From source file:com.impetus.kundera.property.accessor.SQLTimeAccessor.java

@Override
public Time fromString(Class targetClass, String s) {
    if (s == null) {
        return null;
    }//  ww  w  . j a v a  2  s .c  o m

    if (StringUtils.isNumeric(s)) {
        return new Time(Long.parseLong(s));
    }
    Time t = Time.valueOf(s);
    return t;
}

From source file:org.openvpms.archetype.rules.workflow.ScheduleTestHelper.java

/**
 * Helper to create and save new <em>party.organisationSchedule</em>.
 *
 * @param slotSize        the schedule slot size
 * @param slotUnits       the schedule slot units
 * @param noSlots         the appointment no. of slots
 * @param appointmentType the appointment type. May be {@code null}
 * @return a new schedule/*from w ww  .  j a  va 2  s.  c  o m*/
 */
public static Party createSchedule(int slotSize, String slotUnits, int noSlots, Entity appointmentType) {
    Party schedule = (Party) create(ScheduleArchetypes.ORGANISATION_SCHEDULE);
    EntityBean bean = new EntityBean(schedule);
    bean.setValue("name", "XSchedule");
    bean.setValue("slotSize", slotSize);
    bean.setValue("slotUnits", slotUnits);
    bean.setValue("startTime", Time.valueOf("09:00:00"));
    bean.setValue("endTime", Time.valueOf("18:00:00"));
    if (appointmentType != null) {
        addAppointmentType(schedule, appointmentType, noSlots, true);
    }
    bean.save();
    return schedule;
}

From source file:org.openxdata.server.export.rdbms.task.RdmsDataExportTaskTest.java

@Test
public void testSecondTimeExportUpdate() throws Exception {
    // set up test data
    FormData formData = getFormData();//from  www  .  j  a v a  2  s .c om
    FormDefVersion formDefVersion = getFormDefVersion();
    List<DataQuery> updateSql = new ArrayList<DataQuery>();
    Object[] param1 = new Object[] { Time.valueOf("10:44:44"), "female", Time.valueOf("09:44:44"), "0", 61.0,
            "dagmar", 1, "gggg", "ddd", "uganda", null, "mrs", 6, "kisenyi", "123", "azt", "africa",
            java.sql.Date.valueOf("1977-08-20"), "false", "kampala", null, null, "1" };
    String sql1 = "UPDATE patientreg SET endtime=?,sex=?,starttime=?,openxdata_user_id=?,weight=?,openxdata_user_name=?,nokids=?,lastname=?,firstname=?,country=?,picture=?,title=?,height=?,village=?,patientid=?,arvs=?,continent=?,birthdate=?,pregnant=?,district=?,recordvideo=?,coughsound=? WHERE openxdata_form_data_id=?;";
    updateSql.add(new DataQuery(sql1, param1));
    Object[] param2 = new Object[] { "0", "dagmar", 1, "female", "clara", "1", "1" };
    String sql2 = "UPDATE kid SET openxdata_user_id=?,openxdata_user_name=?,kidage=?,kidsex=?,kidname=? WHERE openxdata_form_data_id=? AND parentId = (select Id from patientreg where openxdata_form_data_id=?);";
    updateSql.add(new DataQuery(sql2, param2));

    // set up mock
    EasyMock.expect(exporter.tableExists("", "patientreg")).andReturn(Boolean.TRUE);
    EasyMock.expect(exporter.tableExists("", "kid")).andReturn(Boolean.TRUE);
    // NB: because the tables are already existing, no create table methods, but now we have data existence check
    EasyMock.expect(exporter.dataExists(1, "patientreg")).andReturn(true);
    EasyMock.expect(exporter.dataExists(1, "kid")).andReturn(true);
    exporter.executeSql(updateSql);
    EasyMock.expectLastCall();
    EasyMock.replay(exporter);
    exportService.setFormDataExported(formData, RdmsDataExportTask.EXPORT_TASK_BIT);
    EasyMock.expectLastCall();
    EasyMock.replay(exportService);

    // run test
    st.exportFormData(formData, formDefVersion);

    // verify mock methods were called + assert test ran correctly
    EasyMock.verify(exporter);
}