我正在尝试使用以下方法从Vertica表中检索MAX(ymdh)
。
String query = "SELECT MAX(ymdh) AS ymdh_max FROM table_name";
VerticaDBUtil tjVerticaUtil = VerticaDBUtil.getVerticaRODBUtil();
Jdbi jdbi = tjVerticaUtil.getDbi();
Handle handle = jdbi.open();
List<java.sql.Timestamp> maxYmdhStr = handle.createQuery(query).mapTo(java.sql.Timestamp.class).list();
当我使用JDBI运行原始SQL时,查询返回有效的时间戳,但我在.list()
上收到了NullPointerException。
Exception in thread "main" java.lang.NullPointerException
at com.github.arteam.jdbi3.InstrumentedTimingCollector.collect(InstrumentedTimingCollector.java:34)
at org.jdbi.v3.core.statement.SqlStatements$1.logAfterExecution(SqlStatements.java:153)
at org.jdbi.v3.core.statement.SqlLoggerUtil.wrap(SqlLoggerUtil.java:32)
at org.jdbi.v3.core.statement.SqlStatement.internalExecute(SqlStatement.java:1380)
at org.jdbi.v3.core.result.ResultProducers.lambda$getResultSet$2(ResultProducers.java:68)
at org.jdbi.v3.core.result.ResultIterable.lambda$of$0(ResultIterable.java:53)
at org.jdbi.v3.core.result.ResultIterable.stream(ResultIterable.java:141)
at org.jdbi.v3.core.result.ResultIterable.collect(ResultIterable.java:197)
at org.jdbi.v3.core.result.ResultIterable.list(ResultIterable.java:186)
在使用JDBI检索时间戳时,有人遇到过类似的问题吗?我尝试如下注册java.sql.Timestamp
的行映射器。
jdbi.registerRowMapper(java.sql.Timestamp.class, (rs, ctx) -> rs.getTimestamp("ymdh_max"));
但是我仍然收到NullPointerException。