Implement setTimestamp

This commit is contained in:
김선우
2025-08-28 14:49:16 +09:00
parent 6c93d78394
commit b50011d96b
3 changed files with 55 additions and 12 deletions

View File

@@ -144,7 +144,13 @@ public final class JDBC4PreparedStatement extends JDBC4Statement implements Prep
@Override
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
// TODO
requireNonNull(this.statement);
if (x == null) {
this.statement.bindNull(parameterIndex);
} else {
long time = x.getTime();
this.statement.bindBlob(parameterIndex, ByteBuffer.allocate(Long.BYTES).putLong(time).array());
}
}
@Override
@@ -235,7 +241,8 @@ public final class JDBC4PreparedStatement extends JDBC4Statement implements Prep
@Override
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
// TODO
// TODO: Apply calendar timezone conversion
setTimestamp(parameterIndex, x);
}
@Override

View File

@@ -161,9 +161,6 @@ public final class JDBC4ResultSet implements ResultSet, ResultSetMetaData {
return new Date(time);
}
}
if (result instanceof String) {
return Date.valueOf((String) result);
}
throw new SQLException("Cannot convert value to Date: " + result.getClass());
});
}
@@ -183,9 +180,6 @@ public final class JDBC4ResultSet implements ResultSet, ResultSetMetaData {
return new Time(time);
}
}
if (result instanceof String) {
return Time.valueOf((String) result);
}
throw new SQLException("Cannot convert value to Date: " + result.getClass());
});
}
@@ -193,7 +187,20 @@ public final class JDBC4ResultSet implements ResultSet, ResultSetMetaData {
@Override
@SkipNullableCheck
public Timestamp getTimestamp(int columnIndex) throws SQLException {
throw new UnsupportedOperationException("not implemented");
final Object result = resultSet.get(columnIndex);
if (result == null) {
return null;
}
return wrapTypeConversion(() -> {
if (result instanceof byte[]) {
byte[] bytes = (byte[]) result;
if (bytes.length == Long.BYTES) {
long time = ByteBuffer.wrap(bytes).getLong();
return new Timestamp(time);
}
}
throw new SQLException("Cannot convert value to Timestamp: " + result.getClass());
});
}
@Override
@@ -302,7 +309,7 @@ public final class JDBC4ResultSet implements ResultSet, ResultSetMetaData {
@Override
@SkipNullableCheck
public Timestamp getTimestamp(String columnLabel) throws SQLException {
throw new UnsupportedOperationException("not implemented");
return getTimestamp(findColumn(columnLabel));
}
@Override
@@ -818,13 +825,15 @@ public final class JDBC4ResultSet implements ResultSet, ResultSetMetaData {
@Override
@SkipNullableCheck
public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("not implemented");
// TODO: Apply calendar timezone conversion
return getTimestamp(columnIndex);
}
@Override
@SkipNullableCheck
public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException {
throw new UnsupportedOperationException("not implemented");
// TODO: Apply calendar timezone conversion
return getTimestamp(findColumn(columnLabel));
}
@Override