Java Code Examples for java.sql.ResultSet.getTime()

The following are Jave code examples for showing how to use getTime() of the java.sql.ResultSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: NotifyTools   File: JDBCDynaClass.java   View Source Code Vote up 5 votes
/**
 * Get a column value from a {@link ResultSet} for the specified name.
 *
 * @param resultSet The result set
 * @param name The property name
 * @return The value
 * @throws SQLException if an error occurs
 */
protected Object getObject(final ResultSet resultSet, final String name) throws SQLException {

    final DynaProperty property = getDynaProperty(name);
    if (property == null) {
        throw new IllegalArgumentException("Invalid name '" + name + "'");
    }
    final String columnName = getColumnName(name);
    final Class<?> type = property.getType();

    // java.sql.Date
    if (type.equals(Date.class)) {
        return resultSet.getDate(columnName);
    }

    // java.sql.Timestamp
    if (type.equals(Timestamp.class)) {
        return resultSet.getTimestamp(columnName);
    }

    // java.sql.Time
    if (type.equals(Time.class)) {
        return resultSet.getTime(columnName);
    }

    return resultSet.getObject(columnName);
}
 
Example 2
Project: mm-system-2017   File: DataAccess.java   View Source Code Vote up 5 votes
@Override
public Meeting getMeetingById(int meetingId) throws SQLException {
	Meeting m = null;
	PreparedStatement stm = c.prepareStatement(SQLStatements.selectMeetingById);
	stm.setInt(1, meetingId);
	ResultSet rs = stm.executeQuery();
	if (rs.next()) {

		java.sql.Date SDate = rs.getDate(DataContract.MeetingTable.COL_DATE);

		m = new Meeting(rs.getInt(DataContract.MeetingTable.COL_ACTIVITYID),
				rs.getInt(DataContract.MeetingTable.COL_PAIRID), rs.getInt(DataContract.MeetingTable.COL_MENTORID),
				rs.getInt(DataContract.MeetingTable.COL_MENTEEID), rs.getString(DataContract.MeetingTable.COL_NOTE),
				meetingStatus.valueOf(rs.getInt(DataContract.MeetingTable.COL_STATUS)),
				rs.getString(DataContract.MeetingTable.COL_MENTEEREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTORREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTEEPRIVREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTORPRIVREPORT),
				meetingType.getByValue(rs.getInt(DataContract.MeetingTable.COL_MEETINGTYPE)),
				rs.getString(DataContract.MeetingTable.COL_SUBJECT),
				rs.getString(DataContract.MeetingTable.COL_LOCATION), SDate.getTime(),
				rs.getTime(DataContract.MeetingTable.COL_STARTINGTIME),
				rs.getTime(DataContract.MeetingTable.COL_ENDINGTIME),
				rs.getBoolean(DataContract.MeetingTable.COL_MENTORCOMPLETE),
				rs.getBoolean(DataContract.MeetingTable.COL_MENTEECOMPLETE));

	}
	rs.close();
	stm.close();

	return m;
}
 
Example 3
Project: mm-system-2017   File: DataAccess.java   View Source Code Vote up 5 votes
@Override
public ArrayList<Meeting> getMeetingsByPairId(int pairId) throws SQLException {
	ArrayList<Meeting> m = new ArrayList<Meeting>();
	Meeting meeting = null;

	PreparedStatement stm = c.prepareStatement(SQLStatements.selectMeetingByPairId);
	stm.setInt(1, pairId);
	ResultSet rs = stm.executeQuery();

	while (rs.next()) {
		java.sql.Date SDate = rs.getDate(DataContract.MeetingTable.COL_DATE);

		meeting = new Meeting(rs.getInt(DataContract.MeetingTable.COL_ACTIVITYID),
				rs.getInt(DataContract.MeetingTable.COL_PAIRID), rs.getInt(DataContract.MeetingTable.COL_MENTORID),
				rs.getInt(DataContract.MeetingTable.COL_MENTEEID), rs.getString(DataContract.MeetingTable.COL_NOTE),
				meetingStatus.valueOf(rs.getInt(DataContract.MeetingTable.COL_STATUS)),
				rs.getString(DataContract.MeetingTable.COL_MENTEEREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTORREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTEEPRIVREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTORPRIVREPORT),
				meetingType.getByValue(rs.getInt(DataContract.MeetingTable.COL_MEETINGTYPE)),
				rs.getString(DataContract.MeetingTable.COL_SUBJECT),
				rs.getString(DataContract.MeetingTable.COL_LOCATION), SDate.getTime(),
				rs.getTime(DataContract.MeetingTable.COL_STARTINGTIME),
				rs.getTime(DataContract.MeetingTable.COL_ENDINGTIME),
				rs.getBoolean(DataContract.MeetingTable.COL_MENTORCOMPLETE),
				rs.getBoolean(DataContract.MeetingTable.COL_MENTEECOMPLETE));
		m.add(meeting);
	}
	rs.close();
	stm.close();

	return m;
}
 
Example 4
Project: tangyuan2   File: TimeOnlyTypeHandler.java   View Source Code Vote up 5 votes
@Override
public Date getNullableResult(ResultSet rs, String columnName) throws SQLException {
	java.sql.Time sqlTime = rs.getTime(columnName);
	if (sqlTime != null) {
		return new Date(sqlTime.getTime());
	}
	return null;
}
 
Example 5
Project: tangyuan2   File: TimeOnlyTypeHandler.java   View Source Code Vote up 5 votes
@Override
public Date getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
	java.sql.Time sqlTime = rs.getTime(columnIndex);
	if (sqlTime != null) {
		return new Date(sqlTime.getTime());
	}
	return null;
}
 
Example 6
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 5 votes
public Object getResult(ResultSet rs, String columnName) throws SQLException {

            Object sqlTime = rs.getTime(columnName);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return sqlTime;
            }
        }
 
Example 7
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 5 votes
public Object getResult(ResultSet rs, int columnIndex) throws SQLException {

            Object sqlTime = rs.getTime(columnIndex);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return sqlTime;
            }
        }
 
Example 8
Project: calcite-avatica   File: AvaticaResultSetConversionsTest.java   View Source Code Vote up 5 votes
public void testGetTime(ResultSet resultSet, Calendar calendar) throws SQLException {
  try {
    resultSet.getTime(ordinal, calendar);
    fail("Was expecting to throw SQLDataException");
  } catch (Exception e) {
    assertThat(e, isA((Class) SQLDataException.class)); // success
  }
}
 
Example 9
Project: OpenDiabetes   File: TestDateTime.java   View Source Code Vote up 4 votes
public void testBasicDefaultTimeSupport() throws Throwable {

        final String INSERT_TIME =
            "insert into time_test(time_test) values (?)";

        // See OracleTests class why we need to select tablename.*
        final String SELECT_TIME =
            "select time_test.* from time_test where time_test = ?";
        final String DELETE_TIME = "delete from time_test where time_test = ?";
        java.sql.Time     insertTime;
        Connection        connection = super.newConnection();
        PreparedStatement insertStatement;
        int               iUpdateCount = 0;

        insertTime      = new java.sql.Time(3600000);
        insertStatement = connection.prepareStatement(INSERT_TIME);

        insertStatement.setTime(1, insertTime);

        iUpdateCount = insertStatement.executeUpdate();

        insertStatement.close();
        Assert.assertEquals(
            "Exactly one record with time data shoud have been inserted.",
            iUpdateCount, 1);

        // Now select it back to be sure it is there
        PreparedStatement selectStatement = null;
        PreparedStatement deleteStatement = null;
        ResultSet         results         = null;
        java.sql.Time     retrievedTime;
        int               iDeletedCount = 0;
        java.sql.Time     selectTime;

        selectStatement = connection.prepareStatement(SELECT_TIME);
        selectTime      = new java.sql.Time(3600000);

        selectStatement.setTime(1, selectTime);

        results = selectStatement.executeQuery();

        // Get the date from the database
        Assert.assertTrue("The inserted time is not in the database.",
                          results.next());

        retrievedTime = results.getTime(1);

        //
        deleteStatement = connection.prepareStatement(DELETE_TIME);

        deleteStatement.setTime(1, insertTime);

        iDeletedCount = deleteStatement.executeUpdate();

        Assert.assertEquals(
            "Exactly one record with time data shoud have been deleted.",
            iDeletedCount, 1);

        // And now test the date
        Assert.assertNotNull(
            "The inserted time shouldn't be retrieved as null from the database",
            retrievedTime);

        // Ignore milliseconds when comparing dates
        String  selectString    = selectTime.toString();
        String  retrievedString = retrievedTime.toString();
        boolean result          = retrievedString.equals(selectString);

        Assert.assertTrue(
            "The time retrieved from database "
            + DateFormat.getDateTimeInstance().format(retrievedTime)
            + " is not the same as the inserted one "
            + DateFormat.getDateTimeInstance().format(insertTime), result);
    }
 
Example 10
Project: mm-system-2017   File: DataAccess.java   View Source Code Vote up 4 votes
@SuppressWarnings("resource") // got warning about stm in case 3 not being closed
@Override
public ArrayList<Meeting> getUserMeetings(int id) throws SQLException {
	ArrayList<Meeting> meeting = new ArrayList<Meeting>();
	Meeting meet = null;
	PreparedStatement stm = c.prepareStatement(SQLStatements.selectUserById);
	stm.setInt(1, id);
	ResultSet rs = stm.executeQuery();

	if (rs.next()) {
		int type = rs.getInt(DataContract.UsersTable.COL_TYPE);
		switch (type) {
		case 2:// Mentor
			stm = c.prepareStatement(SQLStatements.selectMeetingsByMentorId);
			break;
		case 3:// Mentee
			stm = c.prepareStatement(SQLStatements.selectMeetingsByMenteeId);
			break;
		default:
			// TODO: LOG ERROR
			rs.close();
			stm.close();

			return null;
		}
	}

	stm.setInt(1, id);
	rs = stm.executeQuery();
	while (rs.next()) {
		java.sql.Date SDate = rs.getDate(DataContract.MeetingTable.COL_DATE);
		meet = new Meeting(rs.getInt(DataContract.MeetingTable.COL_ACTIVITYID),
				rs.getInt(DataContract.MeetingTable.COL_PAIRID), rs.getInt(DataContract.MeetingTable.COL_MENTORID),
				rs.getInt(DataContract.MeetingTable.COL_MENTEEID), rs.getString(DataContract.MeetingTable.COL_NOTE),
				meetingStatus.valueOf(rs.getInt(DataContract.MeetingTable.COL_STATUS)),
				rs.getString(DataContract.MeetingTable.COL_MENTEEREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTORREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTEEPRIVREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTORPRIVREPORT),
				meetingType.getByValue(rs.getInt(DataContract.MeetingTable.COL_MEETINGTYPE)),
				rs.getString(DataContract.MeetingTable.COL_SUBJECT),
				rs.getString(DataContract.MeetingTable.COL_LOCATION), SDate.getTime(),
				rs.getTime(DataContract.MeetingTable.COL_STARTINGTIME),
				rs.getTime(DataContract.MeetingTable.COL_ENDINGTIME),
				rs.getBoolean(DataContract.MeetingTable.COL_MENTORCOMPLETE),
				rs.getBoolean(DataContract.MeetingTable.COL_MENTEECOMPLETE));
		meeting.add(meet);

	}
	rs.close();
	stm.close();

	return meeting;
}
 
Example 11
Project: mm-system-2017   File: DataAccess.java   View Source Code Vote up 4 votes
@Override
public ArrayList<Meeting> getMeetingByStatus(int userId, meetingStatus status, int count, int page)
		throws SQLException {
	ArrayList<Meeting> m = new ArrayList<Meeting>();
	PreparedStatement stm = null;

	userType type = getUser(userId).getType();

	if (type == userType.MENTEE) {
		stm = c.prepareStatement(SQLStatements.getMeetingsByMentee);
	} else if (type == userType.MENTOR) {
		stm = c.prepareStatement(SQLStatements.getMeetingsByMentor);
	} else {
		return null;
	}

	stm.setInt(1, userId);
	stm.setInt(2, status.ordinal());
	stm.setInt(3, (page - 1) * (count));
	stm.setInt(4, count);
	ResultSet rs = stm.executeQuery();
	m = new ArrayList<Meeting>();
	while (rs.next()) {
		java.sql.Date SDate = rs.getDate(DataContract.MeetingTable.COL_DATE);

		Meeting meet = new Meeting(rs.getInt(DataContract.MeetingTable.COL_ACTIVITYID),
				rs.getInt(DataContract.MeetingTable.COL_PAIRID), rs.getInt(DataContract.MeetingTable.COL_MENTORID),
				rs.getInt(DataContract.MeetingTable.COL_MENTEEID), rs.getString(DataContract.MeetingTable.COL_NOTE),
				meetingStatus.valueOf(rs.getInt(DataContract.MeetingTable.COL_STATUS)),
				rs.getString(DataContract.MeetingTable.COL_MENTEEREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTORREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTEEPRIVREPORT),
				rs.getString(DataContract.MeetingTable.COL_MENTORPRIVREPORT),
				meetingType.getByValue(rs.getInt(DataContract.MeetingTable.COL_MEETINGTYPE)),
				rs.getString(DataContract.MeetingTable.COL_SUBJECT),
				rs.getString(DataContract.MeetingTable.COL_LOCATION), SDate.getTime(),
				rs.getTime(DataContract.MeetingTable.COL_STARTINGTIME),
				rs.getTime(DataContract.MeetingTable.COL_ENDINGTIME),
				rs.getBoolean(DataContract.MeetingTable.COL_MENTORCOMPLETE),
				rs.getBoolean(DataContract.MeetingTable.COL_MENTEECOMPLETE));
		m.add(meet);
	}

	rs.close();
	stm.close();

	return m;
}
 
Example 12
Project: dev-courses   File: TestDateTime.java   View Source Code Vote up 4 votes
public void testBasicDefaultTimeSupport() throws Throwable {

        final String INSERT_TIME =
            "insert into time_test(time_test) values (?)";

        // See OracleTests class why we need to select tablename.*
        final String SELECT_TIME =
            "select time_test.* from time_test where time_test = ?";
        final String DELETE_TIME = "delete from time_test where time_test = ?";
        java.sql.Time     insertTime;
        Connection        connection = super.newConnection();
        PreparedStatement insertStatement;
        int               iUpdateCount = 0;

        insertTime      = new java.sql.Time(3600000);
        insertStatement = connection.prepareStatement(INSERT_TIME);

        insertStatement.setTime(1, insertTime);

        iUpdateCount = insertStatement.executeUpdate();

        insertStatement.close();
        Assert.assertEquals(
            "Exactly one record with time data shoud have been inserted.",
            iUpdateCount, 1);

        // Now select it back to be sure it is there
        PreparedStatement selectStatement = null;
        PreparedStatement deleteStatement = null;
        ResultSet         results         = null;
        java.sql.Time     retrievedTime;
        int               iDeletedCount = 0;
        java.sql.Time     selectTime;

        selectStatement = connection.prepareStatement(SELECT_TIME);
        selectTime      = new java.sql.Time(3600000);

        selectStatement.setTime(1, selectTime);

        results = selectStatement.executeQuery();

        // Get the date from the database
        Assert.assertTrue("The inserted time is not in the database.",
                          results.next());

        retrievedTime = results.getTime(1);

        //
        deleteStatement = connection.prepareStatement(DELETE_TIME);

        deleteStatement.setTime(1, insertTime);

        iDeletedCount = deleteStatement.executeUpdate();

        Assert.assertEquals(
            "Exactly one record with time data shoud have been deleted.",
            iDeletedCount, 1);

        // And now test the date
        Assert.assertNotNull(
            "The inserted time shouldn't be retrieved as null from the database",
            retrievedTime);

        // Ignore milliseconds when comparing dates
        String  selectString    = selectTime.toString();
        String  retrievedString = retrievedTime.toString();
        boolean result          = retrievedString.equals(selectString);

        Assert.assertTrue(
            "The time retrieved from database "
            + DateFormat.getDateTimeInstance().format(retrievedTime)
            + " is not the same as the inserted one "
            + DateFormat.getDateTimeInstance().format(insertTime), result);
    }
 
Example 13
Project: aliyun-maxcompute-data-collectors   File: JdbcWritableBridge.java   View Source Code Vote up 4 votes
public static Time readTime(int colNum, ResultSet r) throws SQLException {
  return r.getTime(colNum);
}
 
Example 14
Project: tangyuan2   File: SqlTimeTypeHandler.java   View Source Code Vote up 4 votes
@Override
public Time getNullableResult(ResultSet rs, String columnName) throws SQLException {
	return rs.getTime(columnName);
}
 
Example 15
Project: tangyuan2   File: SqlTimeTypeHandler.java   View Source Code Vote up 4 votes
@Override
public Time getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
	return rs.getTime(columnIndex);
}
 
Example 16
Project: calcite-avatica   File: JdbcResultSet.java   View Source Code Vote up 4 votes
private static Object getValue(ResultSet resultSet, int type, int j,
    Calendar calendar) throws SQLException {
  switch (type) {
  case Types.BIGINT:
    final long aLong = resultSet.getLong(j + 1);
    return aLong == 0 && resultSet.wasNull() ? null : aLong;
  case Types.INTEGER:
    final int anInt = resultSet.getInt(j + 1);
    return anInt == 0 && resultSet.wasNull() ? null : anInt;
  case Types.SMALLINT:
    final short aShort = resultSet.getShort(j + 1);
    return aShort == 0 && resultSet.wasNull() ? null : aShort;
  case Types.TINYINT:
    final byte aByte = resultSet.getByte(j + 1);
    return aByte == 0 && resultSet.wasNull() ? null : aByte;
  case Types.DOUBLE:
  case Types.FLOAT:
    final double aDouble = resultSet.getDouble(j + 1);
    return aDouble == 0D && resultSet.wasNull() ? null : aDouble;
  case Types.REAL:
    final float aFloat = resultSet.getFloat(j + 1);
    return aFloat == 0D && resultSet.wasNull() ? null : aFloat;
  case Types.DATE:
    final Date aDate = resultSet.getDate(j + 1, calendar);
    return aDate == null
        ? null
        : (int) (aDate.getTime() / DateTimeUtils.MILLIS_PER_DAY);
  case Types.TIME:
    final Time aTime = resultSet.getTime(j + 1, calendar);
    return aTime == null
        ? null
        : (int) (aTime.getTime() % DateTimeUtils.MILLIS_PER_DAY);
  case Types.TIMESTAMP:
    final Timestamp aTimestamp = resultSet.getTimestamp(j + 1, calendar);
    return aTimestamp == null ? null : aTimestamp.getTime();
  case Types.ARRAY:
    final Array array = resultSet.getArray(j + 1);
    if (null == array) {
      return null;
    }
    try {
      // Recursively extracts an Array using its ResultSet-representation
      return extractUsingResultSet(array, calendar);
    } catch (UnsupportedOperationException | SQLFeatureNotSupportedException e) {
      // Not every database might implement Array.getResultSet(). This call
      // assumes a non-nested array (depends on the db if that's a valid assumption)
      return extractUsingArray(array, calendar);
    }
  case Types.STRUCT:
    Struct struct = resultSet.getObject(j + 1, Struct.class);
    Object[] attrs = struct.getAttributes();
    List<Object> list = new ArrayList<>(attrs.length);
    for (Object o : attrs) {
      list.add(o);
    }
    return list;
  default:
    return resultSet.getObject(j + 1);
  }
}
 
Example 17
Project: calcite-avatica   File: ColumnMetaData.java   View Source Code Vote up 4 votes
/** Returns the value of a column of this type from a result set. */
public Object jdbcGet(ResultSet resultSet, int i) throws SQLException {
  switch (this) {
  case PRIMITIVE_BOOLEAN:
    return resultSet.getBoolean(i);
  case PRIMITIVE_BYTE:
    return resultSet.getByte(i);
  case PRIMITIVE_SHORT:
    return resultSet.getShort(i);
  case PRIMITIVE_INT:
    return resultSet.getInt(i);
  case PRIMITIVE_LONG:
    return resultSet.getLong(i);
  case PRIMITIVE_FLOAT:
    return resultSet.getFloat(i);
  case PRIMITIVE_DOUBLE:
    return resultSet.getDouble(i);
  case BOOLEAN:
    final boolean aBoolean = resultSet.getBoolean(i);
    return resultSet.wasNull() ? null : aBoolean;
  case BYTE:
    final byte aByte = resultSet.getByte(i);
    return resultSet.wasNull() ? null : aByte;
  case SHORT:
    final short aShort = resultSet.getShort(i);
    return resultSet.wasNull() ? null : aShort;
  case INTEGER:
    final int anInt = resultSet.getInt(i);
    return resultSet.wasNull() ? null : anInt;
  case LONG:
    final long aLong = resultSet.getLong(i);
    return resultSet.wasNull() ? null : aLong;
  case FLOAT:
    final float aFloat = resultSet.getFloat(i);
    return resultSet.wasNull() ? null : aFloat;
  case DOUBLE:
    final double aDouble = resultSet.getDouble(i);
    return resultSet.wasNull() ? null : aDouble;
  case JAVA_SQL_DATE:
    return resultSet.getDate(i);
  case JAVA_SQL_TIME:
    return resultSet.getTime(i);
  case JAVA_SQL_TIMESTAMP:
    return resultSet.getTimestamp(i);
  case ARRAY:
    return resultSet.getArray(i);
  case STRUCT:
    return resultSet.getObject(i, Struct.class);
  default:
    return resultSet.getObject(i);
  }
}
 
Example 18
Project: morpheus-core   File: SQLExtractor.java   View Source Code Vote up 4 votes
@Override
@SuppressWarnings("unchecked")
public <V> V getValue(ResultSet rs, int colIndex) throws SQLException {
    return (V)rs.getTime(colIndex);
}
 
Example 19
Project: morpheus-core   File: SQLExtractor.java   View Source Code Vote up 4 votes
@Override
@SuppressWarnings("unchecked")
public <V> V getValue(ResultSet rs, int colIndex) throws SQLException {
    final Time time = rs.getTime(colIndex);
    return time != null ? (V)time.toLocalTime() : null;
}