Example usage for java.sql ResultSet getTime

List of usage examples for java.sql ResultSet getTime

Introduction

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

Prototype

java.sql.Time getTime(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Time object in the Java programming language.

Usage

From source file:GetDateFromMySql.java

public static void main(String args[]) {
    ResultSet rs = null;
    Connection conn = null;//from   w  ww  .j  a va  2  s.  c  om
    Statement stmt = null;
    try {
        conn = getMySQLConnection();
        stmt = conn.createStatement();
        rs = stmt.executeQuery("select timeCol, dateCol, dateTimeCol from dateTimeTable");
        while (rs.next()) {
            java.sql.Time dbSqlTime = rs.getTime(1);
            java.sql.Date dbSqlDate = rs.getDate(2);
            java.sql.Timestamp dbSqlTimestamp = rs.getTimestamp(3);
            System.out.println("dbSqlTime=" + dbSqlTime);
            System.out.println("dbSqlDate=" + dbSqlDate);
            System.out.println("dbSqlTimestamp=" + dbSqlTimestamp);

            java.util.Date dbSqlTimeConverted = new java.util.Date(dbSqlTime.getTime());
            java.util.Date dbSqlDateConverted = new java.util.Date(dbSqlDate.getTime());
            System.out.println("in standard date");
            System.out.println(dbSqlTimeConverted);
            System.out.println(dbSqlDateConverted);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            rs.close();
            stmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:GetDateFromOracle.java

public static void main(String args[]) {
    String GET_RECORD = "select date_column, time_column, " + "timestamp_column from TestDates where id = ?";
    ResultSet rs = null;
    Connection conn = null;/*w  w  w. j a  va 2  s . c  om*/
    PreparedStatement pstmt = null;
    try {
        conn = getConnection();
        pstmt = conn.prepareStatement(GET_RECORD);
        pstmt.setString(1, "0001");
        rs = pstmt.executeQuery();
        while (rs.next()) {
            java.sql.Date dbSqlDate = rs.getDate(1);
            java.sql.Time dbSqlTime = rs.getTime(2);
            java.sql.Timestamp dbSqlTimestamp = rs.getTimestamp(3);
            System.out.println("dbSqlDate=" + dbSqlDate);
            System.out.println("dbSqlTime=" + dbSqlTime);
            System.out.println("dbSqlTimestamp=" + dbSqlTimestamp);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            rs.close();
            pstmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:wzw.sql.ResultSetConverter.java

/**
 * ?/*  w w w.  j  av  a2 s  . c o m*/
 * @param rs
 * @param type Listjava.sql.Types 
 * @return
 * @throws SQLException
 */
public static Object toType(ResultSet rs, int type) throws SQLException {

    if (rs.next()) { // run rs.next()
        switch (type) {
        case Types.INTEGER:
            return new Integer(rs.getInt(1));

        case Types.BIGINT:
            return new Long(rs.getLong(1));

        case Types.VARCHAR:
            return rs.getString(1);

        case Types.FLOAT:
            return new Float(rs.getFloat(1));

        case Types.DECIMAL:
        case Types.DOUBLE:
        case Types.NUMERIC:
            return new Double(rs.getDouble(1));

        case Types.TIMESTAMP:
            return rs.getTimestamp(1);

        case Types.DATE:
            return rs.getDate(1);

        case Types.TIME:
            return rs.getTime(1);

        default:
            return null;
        }
    }
    return null;

}

From source file:com.wabacus.system.datatype.TimeType.java

public Object getColumnValue(ResultSet rs, int iindex, AbsDatabaseType dbtype) throws SQLException {
    java.sql.Time tt = rs.getTime(iindex);
    if (tt == null)
        return null;
    return new Date(tt.getTime());
}

From source file:com.wabacus.system.datatype.TimeType.java

public Object getColumnValue(ResultSet rs, String column, AbsDatabaseType dbtype) throws SQLException {
    java.sql.Time tt = rs.getTime(column);
    if (tt == null)
        return null;
    return new Date(tt.getTime());
}

From source file:com.wabacus.system.datatype.CTimeType.java

public Object getColumnValue(ResultSet rs, int iindex, AbsDatabaseType dbtype) throws SQLException {
    java.sql.Time ctt = rs.getTime(iindex);
    if (ctt == null)
        return null;
    Calendar cd = Calendar.getInstance();
    cd.setTimeInMillis(ctt.getTime());/*from   w  w w  . java  2  s  .  co  m*/
    return cd;
}

From source file:com.wabacus.system.datatype.CTimeType.java

public Object getColumnValue(ResultSet rs, String column, AbsDatabaseType dbtype) throws SQLException {
    java.sql.Time ctt = rs.getTime(column);
    if (ctt == null)
        return null;
    Calendar cd = Calendar.getInstance();
    cd.setTimeInMillis(ctt.getTime());/* w w w  .java  2 s  .c o  m*/
    return cd;
}

From source file:connectKiosk.Query.java

public void getUserVisits(String email) throws SQLException {

    //statement is hardcoded, only takes the email
    String query = "SELECT users.email, users.fname, users.lname, visits.email, "
            + "visits.visitDate, visits.reason " + " FROM users" + " INNER JOIN visits" + " WHERE users.email='"
            + email + "'" + " ORDER BY visits.visitDate";

    //get results of query
    ResultSet rs = stmt.executeQuery(query);

    //print each line of the query
    while (rs.next()) {
        System.out.print(rs.getString("users.email") + " | " + rs.getString("users.lname") + " | "
                + rs.getDate("visitDate") + " | " + rs.getTime("visitDate") + " | " + rs.getString("reason"));

        System.out.println();//from   ww  w.ja va2s.c  om
    }
}

From source file:wzw.sql.ResultSetConverter.java

/**
 * ?//from w  w w  .  ja  va2  s .  co m
 * @param rs
 * @param type Listjava.sql.Types 
 * @return
 * @throws SQLException
 */
public static List<Object> toTypeList(ResultSet rs, int type) throws SQLException {

    List<Object> list = new ArrayList<Object>();

    switch (type) {
    case Types.INTEGER:
        while (rs.next()) {
            list.add(new Integer(rs.getInt(1)));
        }

    case Types.BIGINT:
        while (rs.next()) {
            list.add(new Long(rs.getLong(1)));
        }

    case Types.VARCHAR:
        while (rs.next()) {
            list.add(rs.getString(1));
        }

    case Types.FLOAT:
        while (rs.next()) {
            list.add(new Float(rs.getFloat(1)));
        }

    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.NUMERIC:
        while (rs.next()) {
            list.add(new Double(rs.getDouble(1)));
        }

    case Types.TIMESTAMP:
        while (rs.next()) {
            list.add(rs.getTimestamp(1));
        }

    case Types.DATE:
        while (rs.next()) {
            list.add(rs.getDate(1));
        }

    case Types.TIME:
        while (rs.next()) {
            list.add(rs.getTime(1));
        }

        //default:
    }
    return list;
}

From source file:com.bt.sdk.callcontrol.demo.standup.ConferenceRowCallbackHandler.java

public void processRow(ResultSet arg0) throws SQLException {
    String conferenceName = arg0.getString("name");
    log.debug(conferenceName);//from w w w.  j  av  a2s  .com

    Calendar conferenceTime = Calendar.getInstance();
    conferenceTime.set(Calendar.HOUR_OF_DAY, arg0.getTime("time").getHours());
    conferenceTime.set(Calendar.MINUTE, arg0.getTime("time").getMinutes());
    conferenceTime.set(Calendar.SECOND, 0);
    conferenceTime.set(Calendar.MILLISECOND, 0);
    String date = DATE_FORMAT.format(Calendar.getInstance().getTime());
    final String key = String.format("%s:%02d%02d:%s", conferenceName, conferenceTime.get(Calendar.HOUR_OF_DAY),
            conferenceTime.get(Calendar.MINUTE), date);
    log.debug(key);
    if (conferenceFutures.containsKey(key)) {
        log.warn(String.format("conference already scheduled: %s", key));
        return;
    }
    final List<String> participants = getParticipants(conferenceName);
    log.debug(participants);
    log.info(String.format("Starting conference \"%s\" in %d seconds", conferenceName,
            secondsBeforeStartTime(conferenceTime)));
    conferenceFutures.put(key, scheduledExecutorService.schedule(new Runnable() {
        public void run() {
            String conferenceId = conferenceBean.createConference(participants.size(),
                    maxConferenceDurationInMinutes);
            conferences.put(conferenceId, key);
            log.debug(conferences);
            for (String participantTelno : participants) {
                String callLegId = conferenceBean.createParticipantCallLeg(conferenceId,
                        URI.create(String.format("sip:%s@%s", participantTelno, pstnGatewayIpAddress)));
                conferenceBean.inviteParticipant(conferenceId, callLegId);
            }
        }
    }, secondsBeforeStartTime(conferenceTime), TimeUnit.SECONDS));
}