本文整理汇总了Java中java.sql.ResultSet.getTimestamp方法的典型用法代码示例。如果您正苦于以下问题:Java ResultSet.getTimestamp方法的具体用法?Java ResultSet.getTimestamp怎么用?Java ResultSet.getTimestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.ResultSet
的用法示例。
在下文中一共展示了ResultSet.getTimestamp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNullableResult
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public Date getNullableResult(ResultSet rs, String columnName) throws SQLException {
Timestamp sqlTimestamp = rs.getTimestamp(columnName);
if (sqlTimestamp != null) {
return new Date(sqlTimestamp.getTime());
}
return null;
}
示例2: newCustomerFromResults
import java.sql.ResultSet; //导入方法依赖的package包/类
/**
* Creates a Customer object from the current row in the given ResultSet.
* The caller is responsible for closing the ResultSet.
* @param rs an open ResultSet positioned to the desired row
* @return the newly created Customer object
* @throws SQLException for problems getting data from row
*/
public static Customer newCustomerFromResults(ResultSet rs)
throws SQLException {
Customer c = new Customer();
// TODO: Use column indices: probably faster?
c.c_first = rs.getString("c_first");
c.c_middle = rs.getString("c_middle");
c.c_street_1 = rs.getString("c_street_1");
c.c_street_2 = rs.getString("c_street_2");
c.c_city = rs.getString("c_city");
c.c_state = rs.getString("c_state");
c.c_zip = rs.getString("c_zip");
c.c_phone = rs.getString("c_phone");
c.c_credit = rs.getString("c_credit");
c.c_credit_lim = rs.getFloat("c_credit_lim");
c.c_discount = rs.getFloat("c_discount");
c.c_balance = rs.getFloat("c_balance");
c.c_ytd_payment = rs.getFloat("c_ytd_payment");
c.c_payment_cnt = rs.getInt("c_payment_cnt");
c.c_since = rs.getTimestamp("c_since");
return c;
}
示例3: testBug54095
import java.sql.ResultSet; //导入方法依赖的package包/类
/**
* Tests fix for BUG#54095 - Unnecessary call in newSetTimestampInternal.
*
* This bug was fixed as a consequence of the patch for Bug#71084.
*
* @throws Exception
* if the test fails.
*/
public void testBug54095() throws Exception {
Connection testConn = getConnectionWithProps("useLegacyDatetimeCode=false");
Calendar testCal = Calendar.getInstance();
java.util.Date origDate = testCal.getTime();
PreparedStatement testPstmt = testConn.prepareStatement("SELECT ?");
testPstmt.setTimestamp(1, new Timestamp(0), testCal);
assertEquals("Calendar object shouldn't have changed after PreparedStatement.setTimestamp().", origDate, testCal.getTime());
ResultSet testRs = testPstmt.executeQuery();
testRs.next();
assertEquals("Calendar object shouldn't have changed after PreparedStatement.executeQuery().", origDate, testCal.getTime());
testRs.getTimestamp(1, testCal);
assertEquals("Calendar object shouldn't have changed after ResultSet.getTimestamp().", origDate, testCal.getTime());
testRs.close();
testPstmt.close();
testConn.close();
}
示例4: mapRow
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public ISubscription mapRow(ResultSet rs, int rowNum) throws SQLException {
Integer subscriptionGroupId = rs.getInt("group_id");
String subscriptionGroupName = rs.getString("group_name");
Long subscriptionGroupGraphId = rs.getLong("group_graph_id");
String graphName = rs.getString("graph_name");
ISubscriptionGroup subscriptionGroup = null;
if (subscriptionGroupId != null &&
subscriptionGroupName != null &&
subscriptionGroupGraphId != null) {
IWayGraph graph = new WayGraph(subscriptionGroupGraphId, graphName);
subscriptionGroup = new SubscriptionGroup(subscriptionGroupId, subscriptionGroupName, graph, new ArrayList<>());
}
ISubscription subscription = new Subscription(
rs.getString("servername"),
rs.getString("viewname"),
subscriptionGroup,
rs.getString("url"),
rs.getString("user"),
rs.getString("password"),
(Date) rs.getTimestamp("timestamp"));
if (subscriptionGroup != null) {
subscription.getSubscriptionGroup().getSubscriptions().add(subscription);
}
return subscription;
}
示例5: FlightLeg
import java.sql.ResultSet; //导入方法依赖的package包/类
/**
* Constructor to auto load flight leg from db
* @param leg_no : primary key of Flight leg
*/
public FlightLeg(int leg_no)
{
this.conn = DBConnect.connect();
PreparedStatement pst = null;
try {
String sql = "SELECT * FROM `flight_leg` WHERE `leg_no` = ?";
pst=conn.prepareStatement(sql);
pst.setInt(1,leg_no);
ResultSet rs;
rs = pst.executeQuery();
if (!rs.isBeforeFirst() ) {
return;
}
while (rs.next()) {
this.leg_no = rs.getInt("leg_no");
this.leg_type = rs.getString("leg_type");
this.from_aID = rs.getString("from_aID");
this.to_aID = rs.getString("to_aID");
this.departure_time = rs.getTimestamp("departure_time");
this.arival_time = rs.getTimestamp("arival_time");
this.flight_no = rs.getString("flight_no");
this.exist = true;
}
} catch (SQLException e) {
System.out.println("Error : while excicuting prepared statement");
System.out.println(e);
}
}
示例6: contentiousWork
import java.sql.ResultSet; //导入方法依赖的package包/类
/**
* @param threadConn
* @param threadStmt
* @param threadNumber
*/
void contentiousWork(Connection threadConn, Statement threadStmt, int threadNumber) {
Date now = new Date();
try {
for (int i = 0; i < 1000; i++) {
ResultSet threadRs = threadStmt.executeQuery("SELECT 1, 2");
while (threadRs.next()) {
threadRs.getString(1);
threadRs.getString(2);
}
threadRs.close();
PreparedStatement pStmt = threadConn.prepareStatement("SELECT ?");
pStmt.setTimestamp(1, new Timestamp(now.getTime()));
threadRs = pStmt.executeQuery();
while (threadRs.next()) {
threadRs.getTimestamp(1);
}
threadRs.close();
pStmt.close();
}
} catch (Exception ex) {
throw new RuntimeException(ex.toString());
}
}
示例7: map
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public DBPixelPlacement map(int index, ResultSet r, StatementContext ctx) throws SQLException {
Timestamp time = r.getTimestamp("time");
Timestamp ban_expiry = r.getTimestamp("users.ban_expiry");
boolean banned = Role.valueOf(r.getString("users.role")) == Role.BANNED;
if (!banned && ban_expiry != null) {
banned = ban_expiry.getTime() > System.currentTimeMillis();
}
return new DBPixelPlacement(
r.getInt("id"),
r.getInt("x"),
r.getInt("y"),
r.getInt("color"),
r.getInt("secondary_id"),
time == null ? 0 : time.getTime(),
r.getInt("users.id"),
r.getString("users.username"),
r.getString("users.login"),
Role.valueOf(r.getString("users.role")), // TODO: all users might not have valid roles
ban_expiry == null ? 0 : ban_expiry.getTime(),
r.getInt("pixel_count"),
r.getInt("pixel_count_alltime"),
r.getString("users.ban_reason"),
banned,
r.getBoolean("undo_action"),
r.getString("user_agent")
);
}
示例8: Payment
import java.sql.ResultSet; //导入方法依赖的package包/类
public Payment(ResultSet rs) throws SQLException
{
payid = (UUID)rs.getObject("payid");
eventid = (UUID)rs.getObject("eventid");
carid = (UUID)rs.getObject("carid");
refid = rs.getString("refid");
txtype = rs.getString("txtype");
txid = rs.getString("txid");
txtime = rs.getTimestamp("txtime", Database.utc);
itemname = rs.getString("itemname");
amount = rs.getDouble("amount");
}
示例9: mapRow
import java.sql.ResultSet; //导入方法依赖的package包/类
public MediaFile mapRow(ResultSet rs, int rowNum) throws SQLException {
return new MediaFile(
rs.getInt(1),
rs.getString(2),
rs.getString(3),
MediaFile.MediaType.valueOf(rs.getString(4)),
rs.getString(5),
rs.getString(6),
rs.getString(7),
rs.getString(8),
rs.getString(9),
rs.getInt(10) == 0 ? null : rs.getInt(10),
rs.getInt(11) == 0 ? null : rs.getInt(11),
rs.getInt(12) == 0 ? null : rs.getInt(12),
rs.getString(13),
rs.getInt(14) == 0 ? null : rs.getInt(14),
rs.getBoolean(15),
rs.getInt(16) == 0 ? null : rs.getInt(16),
rs.getLong(17) == 0 ? null : rs.getLong(17),
rs.getInt(18) == 0 ? null : rs.getInt(18),
rs.getInt(19) == 0 ? null : rs.getInt(19),
rs.getString(20),
rs.getString(21),
rs.getInt(22),
rs.getTimestamp(23),
rs.getString(24),
rs.getTimestamp(25),
rs.getTimestamp(26),
rs.getTimestamp(27),
rs.getTimestamp(28),
rs.getBoolean(29),
rs.getInt(30));
}
示例10: getValuesInRange
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
public Set<SensorValue<Boolean>> getValuesInRange(Date start, Date end) {
NavigableSet<SensorValue<Boolean>> ret = new TreeSet<>();
try (Connection conn = dbMan.getConnection()) {
try (PreparedStatement stmt = conn.prepareStatement(SELECT_RANGE)) {
stmt.setLong(1, dbId);
stmt.setTimestamp(2, new Timestamp(start.getTime()));
long endTime = end == null ? System.currentTimeMillis() : end.getTime();
stmt.setTimestamp(3, new Timestamp(endTime));
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
SensorValue<Boolean> val = new SensorValue<>(rs.getTimestamp("CREATED"), rs.getBoolean("PRESENCE"));
ret.add(val);
}
}
} catch (SQLException ex) {
LOG.error("Error querying light values", ex);
}
return ret;
}
示例11: getValue
import java.sql.ResultSet; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <V> V getValue(ResultSet rs, int colIndex) throws SQLException {
return (V)rs.getTimestamp(colIndex);
}
示例12: mapRow
import java.sql.ResultSet; //导入方法依赖的package包/类
public Share mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Share(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getTimestamp(5),
rs.getTimestamp(6), rs.getTimestamp(7), rs.getInt(8));
}
示例13: mapRow
import java.sql.ResultSet; //导入方法依赖的package包/类
public Position mapRow(ResultSet rs, int rowNum) throws SQLException {
Position.Builder builder = Position.newBuilder();
if (rs.getString("inst_id") != null)
builder.setInstId(rs.getString("inst_id"));
if (rs.getString("portf_id") != null)
builder.setPortfId(rs.getString("portf_id"));
builder.setTotalQty(rs.getDouble("total_qty"));
builder.setTotalBuyQty(rs.getDouble("total_buy_qty"));
builder.setTotalSellQty(rs.getDouble("total_sell_qty"));
builder.setAvgSellPrice(rs.getDouble("avg_buy_price"));
builder.setAvgSellPrice(rs.getDouble("avg_sell_price"));
if (rs.getTimestamp("timestamp") != null)
builder.setTimestamp(rs.getTimestamp("timestamp").getTime());
return builder.build();
}
示例14: getValue
import java.sql.ResultSet; //导入方法依赖的package包/类
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);
}
}
示例15: jdbcGet
import java.sql.ResultSet; //导入方法依赖的package包/类
/** 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);
}
}