Oracle JDBC无法取得时分秒
七月 23, 2009 in Java开源
在项目中使用的Oracle JDBC版本为Oracle JDBC Driver version – 9.0.2.0.0,由于使用了Hibernate,所以一直没有发现使用native sql查询时时间类型会丢失时分秒。测试程序如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | public class TestDate { public static void main(String[] args) { Connection connection = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); try { connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","exthosf","exthosf"); PreparedStatement ps=connection.prepareStatement("SELECT sysdate FROM dual"); ResultSet rs=ps.executeQuery(); while(rs.next()) System.out.println(rs.getObject(1)); } catch (SQLException e) { e.printStackTrace(); } if (connection != null) { System.out.println("取得连接 :)"); } else { System.out.println("无法取得数据库连接!"); } } catch (ClassNotFoundException e) { System.out.println("无法找到数据库连接驱动!"); e.printStackTrace(); } finally { try { // 检查连接是否为空,如果不为空则关闭 if (connection != null) { connection.close(); } } catch (SQLException e) { System.out.println("关闭连接时发生错误"); } } } } |
使用Oracle JDBC Driver version – 9.0.2.0.0 得到的结果如下:
2009-08-05
取得连接
作用 Oracle JDBC Driver version – “11.1.0.6.0-Production*” 得到的结果如下:
2009-08-05 20:12:27.0
取得连接
相关文章: