Example usage for java.sql Time getMinutes

List of usage examples for java.sql Time getMinutes

Introduction

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

Prototype

@Deprecated
public int getMinutes() 

Source Link

Document

Returns the number of minutes past the hour represented by this date, as interpreted in the local time zone.

Usage

From source file:com.google.visualization.datasource.util.SqlDataSourceHelper.java

/**
 * Creates a table cell from the value in the current row of the given result
 * set and the given column index. The type of the value is determined by the
 * given value type.//  www.j a v a2s . co m
 *
 * @param rs The result set holding the data from the sql table. The result
 *     points to the current row.
 * @param valueType The value type of the column that the cell belongs to.
 * @param column The column index. Indexes are 0-based.
 *
 * @return The table cell.
 *
 * @throws SQLException Thrown when the connection to the database failed.
 */
private static TableCell buildTableCell(ResultSet rs, ValueType valueType, int column) throws SQLException {
    Value value = null;

    // SQL indexes are 1- based.
    column = column + 1;

    switch (valueType) {
    case BOOLEAN:
        value = BooleanValue.getInstance(rs.getBoolean(column));
        break;
    case NUMBER:
        value = new NumberValue(rs.getDouble(column));
        break;
    case DATE:
        Date date = rs.getDate(column);
        // If date is null it is handled later.
        if (date != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the year, month and date in the gregorian calendar.
            // Use the 'set' method with those parameters, and not the 'setTime'
            // method with the date parameter, since the Date object contains the
            // current time zone and it's impossible to change it to 'GMT'.
            gc.set(date.getYear() + 1900, date.getMonth(), date.getDate());
            value = new DateValue(gc);
        }
        break;
    case DATETIME:
        Timestamp timestamp = rs.getTimestamp(column);
        // If timestamp is null it is handled later.
        if (timestamp != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the year, month, date, hours, minutes and seconds in the
            // gregorian calendar. Use the 'set' method with those parameters,
            // and not the 'setTime' method with the timestamp parameter, since
            // the Timestamp object contains the current time zone and it's
            // impossible to change it to 'GMT'.
            gc.set(timestamp.getYear() + 1900, timestamp.getMonth(), timestamp.getDate(), timestamp.getHours(),
                    timestamp.getMinutes(), timestamp.getSeconds());
            // Set the milliseconds explicitly, as they are not saved in the
            // underlying date.
            gc.set(Calendar.MILLISECOND, timestamp.getNanos() / 1000000);
            value = new DateTimeValue(gc);
        }
        break;
    case TIMEOFDAY:
        Time time = rs.getTime(column);
        // If time is null it is handled later.
        if (time != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the hours, minutes and seconds of the time in the gregorian
            // calendar. Set the year, month and date to be January 1 1970 like
            // in the Time object.
            // Use the 'set' method with those parameters,
            // and not the 'setTime' method with the time parameter, since
            // the Time object contains the current time zone and it's
            // impossible to change it to 'GMT'.
            gc.set(1970, Calendar.JANUARY, 1, time.getHours(), time.getMinutes(), time.getSeconds());
            // Set the milliseconds explicitly, otherwise the milliseconds from
            // the time the gc was initialized are used.
            gc.set(GregorianCalendar.MILLISECOND, 0);
            value = new TimeOfDayValue(gc);
        }
        break;
    default:
        String colValue = rs.getString(column);
        if (colValue == null) {
            value = TextValue.getNullValue();
        } else {
            value = new TextValue(rs.getString(column));
        }
        break;
    }
    // Handle null values.
    if (rs.wasNull()) {
        return new TableCell(Value.getNullValueFromValueType(valueType));
    } else {
        return new TableCell(value);
    }
}

From source file:main.UIController.java

@SuppressWarnings("deprecation")
public void convertToImladris() {
    UI window = this.getUi();

    String errorEmptyYear = "Please insert a year.";
    String errorYearNotNumeric = "Please insert the year as a numeric value.";
    String errorYearNotValid = "Please insert a valid year (from 1 to "
            + Integer.toString(GregorianInfo.MAX_SUPPORTED_YEAR) + ").";
    String errorDayNotRead = "Sorry, the day could not be read.";

    JTextField year = window.getYear();
    JComboBox month = window.getMonth();
    JComboBox day = window.getDay();
    JCheckBox afterSunset = window.getAfterSunset();
    JTextPane result = window.getResImladris();
    String value = year.getText();
    if (!value.isEmpty()) {
        try {/*from  www . j a va  2s  .  c  o  m*/
            int yearNum = Integer.parseInt(value);
            if (yearNum > 0 && yearNum <= GregorianInfo.MAX_SUPPORTED_YEAR) {
                int monthNum = month.getSelectedIndex() + 1;
                int dayNum = 0;
                if (day.isEnabled()) {
                    dayNum = day.getSelectedIndex() + 1;
                    ImladrisCalendar cal;
                    if (afterSunset.isSelected()) {
                        GregorianCalendar gcal = new GregorianCalendar(yearNum, monthNum, dayNum);
                        Time time = this.calculateSunsetForActualLocation(gcal, true);
                        cal = new ImladrisCalendar(time, yearNum, monthNum, dayNum, time.getHours(),
                                time.getMinutes(), time.getSeconds());
                    } else {
                        cal = new ImladrisCalendar(yearNum, monthNum, dayNum);
                    }
                    result.setText(cal.toString());
                } else {
                    result.setText(errorDayNotRead);
                }
            } else {
                result.setText(errorYearNotValid);
            }
        } catch (NumberFormatException e) {
            result.setText(errorYearNotNumeric);
        }
    } else {
        result.setText(errorEmptyYear);
    }
}

From source file:org.apache.tajo.storage.jdbc.JdbcScanner.java

protected void convertTuple(ResultSet resultSet, VTuple tuple) {
    try {/*from   ww  w  . j  av  a  2  s . c o m*/
        for (int column_idx = 0; column_idx < targets.length; column_idx++) {
            final Column c = targets[column_idx];
            final int resultIdx = column_idx + 1;

            switch (c.getDataType().getType()) {
            case INT1:
            case INT2:
                tuple.put(column_idx, DatumFactory.createInt2(resultSet.getShort(resultIdx)));
                break;
            case INT4:
                tuple.put(column_idx, DatumFactory.createInt4(resultSet.getInt(resultIdx)));
                break;
            case INT8:
                tuple.put(column_idx, DatumFactory.createInt8(resultSet.getLong(resultIdx)));
                break;
            case FLOAT4:
                tuple.put(column_idx, DatumFactory.createFloat4(resultSet.getFloat(resultIdx)));
                break;
            case FLOAT8:
                tuple.put(column_idx, DatumFactory.createFloat8(resultSet.getDouble(resultIdx)));
                break;
            case CHAR:
                tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx)));
                break;
            case VARCHAR:
            case TEXT:
                // TODO - trim is unnecessary in many cases, so we can use it for certain cases
                tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx).trim()));
                break;
            case DATE:
                final Date date = resultSet.getDate(resultIdx);
                tuple.put(column_idx,
                        DatumFactory.createDate(1900 + date.getYear(), 1 + date.getMonth(), date.getDate()));
                break;
            case TIME:
                final Time time = resultSet.getTime(resultIdx);
                tuple.put(column_idx, new TimeDatum(
                        DateTimeUtil.toTime(time.getHours(), time.getMinutes(), time.getSeconds(), 0)));
                break;
            case TIMESTAMP:
                tuple.put(column_idx, DatumFactory
                        .createTimestampDatumWithJavaMillis(resultSet.getTimestamp(resultIdx).getTime()));
                break;
            case BINARY:
            case VARBINARY:
            case BLOB:
                tuple.put(column_idx, DatumFactory.createBlob(resultSet.getBytes(resultIdx)));
                break;
            default:
                throw new TajoInternalError(new UnsupportedDataTypeException(c.getDataType().getType().name()));
            }
        }
    } catch (SQLException s) {
        throw new TajoInternalError(s);
    }
}