Java examples for java.sql:ResultSet
retrieves a time value from the resultset at the given column.
//package com.java2s; import java.sql.CallableStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Calendar; public class Main { /**/*from ww w .j a v a2 s. com*/ * This method retrieves a time value from the resultset at the given * column. If the column's value is null, null is returned, else a new * Calendar object containing the date value is returned. * @param result The result from which the value is to be retrieved. * @param columnIndex The index of the column from which the value is to * be retrieved. * @return If the column's value is null, null; else a new Calendar object * containing the date value in the column. * @throws SQLException Indicates an error retrieving the data from the * ResultSet. */ public static Calendar getNullableTime(ResultSet result, int columnIndex) throws SQLException { java.util.Date data = result.getTime((columnIndex)); if (result.wasNull()) { return null; } else { Calendar cal = Calendar.getInstance(); cal.setTime(data); return cal; } } /** * This method retrieves a time value from the callable statement at the * given parameter. If the parameter's value is null, null is returned, * else a new Calendar object containing the date value is returned. * @param stmt The callable statement from which the value is to be * retrieved. * @param paramIndex The index of the parameter from which the value is to * be retrieved. * @return If the parameter's value is null, null; else a new Calendar * object containing the date value in the parameter. * @throws SQLException Indicates an error retrieving the data from the * CallableStatement. */ public static Calendar getNullableTime(CallableStatement stmt, int paramIndex) throws SQLException { java.util.Date date = stmt.getTime(paramIndex); if (stmt.wasNull()) { return null; } else { Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal; } } }