Example usage for java.sql Date getMonth

List of usage examples for java.sql Date getMonth

Introduction

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

Prototype

@Deprecated
public int getMonth() 

Source Link

Document

Returns a number representing the month that contains or begins with the instant in time represented by this Date object.

Usage

From source file:History.PieChart_DB.java

public static void main(String[] args) throws Exception {

    String mobilebrands[] = { "IPhone 5s", "SamSung Grand", "MotoG", "Nokia Lumia" };
    int statOfRepair = 0;
    java.util.Date now = new java.util.Date();
    String adminDate = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate();
    /* Create MySQL Database Connection */
    Class.forName("com.mysql.jdbc.Driver");
    Connection connect = ConnectDatabase.connectDb("win", "win016");

    Statement statement = connect.createStatement();
    ResultSet resultSet = statement
            .executeQuery("SELECT COUNT(transID) AS statRepair FROM `Transaction` WHERE dateTime LIKE \'"
                    + adminDate + "%\' AND action LIKE 'Repair'");
    DefaultPieDataset dataset = new DefaultPieDataset();

    while (resultSet.next()) {
        dataset.setValue(resultSet.getString("statRepair"),
                Double.parseDouble(resultSet.getString("unit_sale")));
    }//ww  w  .j  a v  a2  s  . c om

    JFreeChart chart = ChartFactory.createPieChart("History", // chart title           
            dataset, // data           
            true, // include legend          
            true, false);

    int width = 560; /* Width of the image */
    int height = 370; /* Height of the image */
    File pieChart = new File("Pie_Chart.jpeg");
    ChartUtilities.saveChartAsJPEG(pieChart, chart, width, height);
}

From source file:org.kuali.kra.subaward.service.impl.SubAwardServiceImpl.java

@Override
public String getCalculatedFollowupDateForAjaxCall(String baseDate) {
    final String empty = "";
    String[] elements = baseDate.split("/");
    if (elements.length == 3) {
        try {//w  w  w .  j  ava 2s  .c o m
            int month = Integer.parseInt(elements[0]);
            int day = Integer.parseInt(elements[1]);
            int year = Integer.parseInt(elements[2]);
            if (year < 100) {
                year = year + 2000;
            }
            Date requestedDate = new Date(year, month - 1, day - 1);
            Date followUpDate = getCalculatedFollowupDate(requestedDate);
            return (followUpDate.getMonth() + 1) + "/" + (followUpDate.getDate() + 1) + "/"
                    + followUpDate.getYear();

        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
    }
    return empty;
}

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.//ww  w.  j ava  2s  .c o 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:com.hichinaschool.flashcards.libanki.Utils.java

/**
 * Returns the proleptic Gregorian ordinal of the date, where January 1 of year 1 has ordinal 1.
 * @param date Date to convert to ordinal, since 01/01/01
 * @return The ordinal representing the date
 *//*from  w w  w. j  av a  2s  . c  om*/
public static int dateToOrdinal(Date date) {
    // BigDate.toOrdinal returns the ordinal since 1970, so we add up the days from 01/01/01 to 1970
    return BigDate.toOrdinal(date.getYear() + 1900, date.getMonth() + 1, date.getDate()) + DAYS_BEFORE_1970;
}

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

protected void convertTuple(ResultSet resultSet, VTuple tuple) {
    try {/*from ww  w.  ja va  2s .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);
    }
}

From source file:org.arasthel.almeribus.Principal.java

@Override
public void onPostCreate(Bundle savedInstanceState) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    long ultimaActualizacion = sp.getLong("ultima_actualizacion", 0);
    Date fechaUltima = new Date(ultimaActualizacion);
    long nuevoTiempo = System.currentTimeMillis();
    Date nuevaFecha = new Date(nuevoTiempo);

    necesitaActualizacion = false;//from  w  w w .ja  v  a  2s .c  o m

    if (nuevaFecha.getDay() != fechaUltima.getDay() || nuevaFecha.getMonth() != fechaUltima.getMonth()
            || nuevaFecha.getYear() != fechaUltima.getYear()) {
        necesitaActualizacion = true;
    }

    // We load the bus stop info from Surbus server
    cargarParadas();
    if (savedInstanceState == null && !necesitaActualizacion && !loaded) {
        savedInstanceState = new Bundle();
        savedInstanceState.putBoolean("SlidingActivityHelper.open", true);
    }
    super.onPostCreate(savedInstanceState);
}