我想将 (Oracle) 数据库的 systimestamp 转换为 java.sql.Timestamp。以下是测试该过程的部分代码:
我得到的输出是:
try {
conn = this.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("SELECT SYSTIMESTAMP FROM DUAL");
ResultSet rs = stmt.getResultSet();
ResultSetMetaData rsm = rs.getMetaData();
while(rs.next()) {
TIMESTAMPTZ ts = (TIMESTAMPTZ) rs.getObject(1);
System.out.println(ts);
System.out.println(ts.getClass());
System.out.println(ts.timestampValue());
}
} catch (SQLException e) {
e.printStackTrace();
System.out.println(e);
}
我得到的输出是:
oracle.sql.TIMESTAMPTZ@1e97f9f
class oracle.sql.TIMESTAMPTZ
and then an exception:
java.sql.SQLException: Conversion to Timestamp failed
at oracle.sql.Datum.timestampValue(Datum.java:283)
at com.sumawest.test.model.UnitTest.testTimezone(UnitTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at oracle.jdevimpl.junit.runner.TestRunner.doRun(TestRunner.java:111)
at oracle.jdevimpl.junit.runner.TestRunner.start(TestRunner.java:91)
at oracle.jdevimpl.junit.runner.TestRunner.main(TestRunner.java:43)
java.sql.SQLException: Conversion to Timestamp failed
有人有办法解决这个问题吗?
java.sql.Timestamp
? - AlikElzin-kilaka