Example usage for java.sql Time Time

List of usage examples for java.sql Time Time

Introduction

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

Prototype

public Time(long time) 

Source Link

Document

Constructs a Time object using a milliseconds time value.

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[] argv) throws Exception {
    String driverName = "com.jnetdirect.jsql.JSQLDriver";
    Class.forName(driverName);/* w  ww .ja v a2 s  . c o  m*/

    String serverName = "127.0.0.1";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String url = "jdbc:JSQLConnect://" + mydatabase;
    String username = "username";
    String password = "password";

    Connection connection = DriverManager.getConnection(url, username, password);
    String sql = "INSERT INTO mysql_all_table(" + "col_boolean," + "col_byte," + "col_short," + "col_int,"
            + "col_long," + "col_float," + "col_double," + "col_bigdecimal," + "col_string," + "col_date,"
            + "col_time," + "col_timestamp," + "col_asciistream," + "col_binarystream," + "col_blob) "
            + "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    PreparedStatement pstmt = connection.prepareStatement(sql);

    pstmt.setBoolean(1, true);
    pstmt.setByte(2, (byte) 123);
    pstmt.setShort(3, (short) 123);
    pstmt.setInt(4, 123);
    pstmt.setLong(5, 123L);
    pstmt.setFloat(6, 1.23F);
    pstmt.setDouble(7, 1.23D);
    pstmt.setBigDecimal(8, new BigDecimal(1.23));
    pstmt.setString(9, "a string");
    pstmt.setDate(10, new java.sql.Date(System.currentTimeMillis()));
    pstmt.setTime(11, new Time(System.currentTimeMillis()));
    pstmt.setTimestamp(12, new Timestamp(System.currentTimeMillis()));

    File file = new File("infilename1");
    FileInputStream is = new FileInputStream(file);
    pstmt.setAsciiStream(13, is, (int) file.length());

    file = new File("infilename2");
    is = new FileInputStream(file);
    pstmt.setBinaryStream(14, is, (int) file.length());

    file = new File("infilename3");
    is = new FileInputStream(file);
    pstmt.setBinaryStream(15, is, (int) file.length());

    pstmt.executeUpdate();
}

From source file:Main.java

public static Time dateToSQLTime(java.util.Date d) {

    return d != null ? new Time(d.getTime()) : null;
}

From source file:Main.java

/**
 * Parse time string to Time "HH:mm:ss".
 *
 * @param timeStr/*from w  w w .j av a  2 s .com*/
 * @return Date
 */
public static Time parseTime(String timeStr) {
    try {
        return new Time(TIME_FORMATTER.parse(timeStr).getTime());
    } catch (Exception e) {
        return null;
    }
}

From source file:ConversionUtil.java

/**
 * convert into java.sql.Time (or into java.util.Calendar
 * // www. j  a  va2 s  . c o m
 * @param date
 *          The date containing the time.
 * @param am
 *          Whether this should be am (true) or pm (false)
 * @return
 */
public static Time convertDateToTime(Date date, boolean am) {
    if (date == null) {
        return null;
    }

    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    int hourOfDay = cal.get(Calendar.HOUR_OF_DAY);

    if (am) {
        // Check to make sure that the hours are indeed am hours
        if (hourOfDay > 11) {
            cal.set(Calendar.HOUR_OF_DAY, hourOfDay - 12);
            date.setTime(cal.getTimeInMillis());
        }
    } else {
        // Check to make sure that the hours are indeed pm hours
        if (cal.get(Calendar.HOUR_OF_DAY) < 11) {
            cal.set(Calendar.HOUR_OF_DAY, hourOfDay + 12);
            date.setTime(cal.getTimeInMillis());
        }
    }
    return new Time(date.getTime());
}

From source file:com.yahoo.elide.utils.coerce.converters.EpochToDateConverter.java

private static <T> T longToDate(Class<T> cls, Long epoch) throws ReflectiveOperationException {
    if (ClassUtils.isAssignable(cls, java.sql.Date.class)) {
        return (T) new java.sql.Date(epoch);
    } else if (ClassUtils.isAssignable(cls, Timestamp.class)) {
        return (T) new Timestamp(epoch);
    } else if (ClassUtils.isAssignable(cls, Time.class)) {
        return (T) new Time(epoch);
    } else if (ClassUtils.isAssignable(cls, Date.class)) {
        return (T) new Date(epoch);
    } else {//  www .  j av a 2s .co  m
        throw new UnsupportedOperationException("Cannot convert to " + cls.getSimpleName());
    }
}

From source file:com.microsoft.sqlserver.testframework.sqlType.SqlTime.java

public SqlTime() {
    super("time", JDBCType.TIME, null, null);
    type = java.sql.Time.class;
    try {//www  .jav  a 2 s  .c om
        minvalue = new Time(dateFormat.parse((String) SqlTypeValue.TIME.minValue).getTime());
        maxvalue = new Time(dateFormat.parse((String) SqlTypeValue.TIME.maxValue).getTime());
    } catch (ParseException ex) {
        fail(ex.getMessage());
    }
    this.precision = 7;
    this.variableLengthType = VariableLengthType.Precision;
    generatePrecision();
    formatter = new DateTimeFormatterBuilder().appendPattern(basePattern)
            .appendFraction(ChronoField.NANO_OF_SECOND, 0, this.precision, true).toFormatter();

}

From source file:de.interseroh.report.formatters.TimeFormatter.java

@Override
public Time parse(String text, Locale locale) throws ParseException {
    java.util.Date parsed = getDateFormat(locale).parse(text);
    return new Time(parsed.getTime());
}

From source file:TestReservasSalas.java

@Test
public void testDisponibilidadSala() throws OperationFailedException {
    Establecimiento e = new Establecimiento(1, "El toque", "123.456.789-1", "calle falsa 123", new Time(700),
            new Time(1900), 0, "Usaquen", "1234567", "34301293809213820921");
    logica.registrarEstablecimiento(e);//www. j  av  a 2 s  .  co m
    Sala s = new Sala(1, logica.consultarEstablecimiento(1), "1000", "Sala de Orcas");
    logica.registrarSala(s);
    Date d = new Date();
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(d);
    Time t = new Time(gc.getTime().getTime());

    assertTrue(logica.verificarDisponibilidadSala(d, t, s.getIdSala(), 1));

    Reservacion r = new Reservacion(1, s, d, t, 1);
    //s.getReservacions().add(r);
    String resp = logica.registrarReserva(e.getIdEstablecimiento(), s.getIdSala(), d, t, 2);

    assertFalse(logica.verificarDisponibilidadSala(d, t, s.getIdSala(), 1));
    List<Reservacion> l = logica.consultarReservacionesPorSala(s.getIdSala());
    System.out.println(l.get(0).getFecha().toString());

    Cliente c = new Cliente(1016040342, "ORCA");
    logica.registrarCliente(c);

    for (Reservacion rs : l) {
        if (rs.getFecha().equals(r.getFecha()))
            r = rs;
    }
    r.setIdReservacion(0);
    if (resp.equals("0"))
        logica.crearEnsayoAlquiler(c.getIdCliente(), r, "ensayaremos mucho");

}

From source file:TestPublicarEstablecimiento.java

@Test
@Transactional/* w ww .  ja v a 2s  .c  om*/
@Rollback(true)
public void testRegistrarEstablecimiento() throws OperationFailedException {
    int limite = 500;
    ArrayList<Establecimiento> listaEsta = new ArrayList<>();
    for (int i = 400; i < limite; i++) {
        Establecimiento a = new Establecimiento(i, "nombre" + i, i + ".123.123-1", "Autonorte" + i,
                new Time(700), new Time(1800), 2.0, "Puente Aranda", "1234567890", "34523456435454423439");
        listaEsta.add(a);
        logica.registrarEstablecimiento(a);
    }

    Establecimiento fd;
    for (int i = 400; i < limite; i++) {
        fd = logica.consultarEstablecimiento(i);
        assertEquals(listaEsta.get(i - 400).getIdEstablecimiento(), fd.getIdEstablecimiento());
        assertEquals(listaEsta.get(i - 400).getNombre(), fd.getNombre());
        assertEquals(listaEsta.get(i - 400).getNit(), fd.getNit());
        assertEquals(listaEsta.get(i - 400).getDireccion(), fd.getDireccion());
        assertEquals(listaEsta.get(i - 400).getHoraInicio(), fd.getHoraInicio());
        assertEquals(listaEsta.get(i - 400).getHoraCierre(), fd.getHoraCierre());
        assertEquals(listaEsta.get(i - 400).getLocalidad(), fd.getLocalidad());
        assertEquals(listaEsta.get(i - 400).getTelefono(), fd.getTelefono());
    }
}