我正在使用“Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production with the Partitioning、OLAP、Data Mining 和 Real Application Testing 选项”
我有一个表,其架构是
COLUMN_NAME DATA_TYPE DATA_TYPE_MOD DATA_TYPE_OWNER DATA_LENGTH
CITY VARCHAR2 (null) (null) 30
COUNTRY VARCHAR2 (null) (null) 30
DATE_TYPE DATE (null) (null) 7
PARTNO NUMBER (null) (null) 22
STATE VARCHAR2 (null) (null) 30
ZIP VARCHAR2 (null) (null) 30
我编写了一个简单的 java 客户端来获取DATE_TYPE
.
public class DateIssue {
private void testDateOutput() {
Connection con = null;
Statement psmt = null;
try {
con = getConnection();
con.setAutoCommit(true);
psmt = con.createStatement();
String sql = "SELECT DATE_TYPE FROM EMP";
ResultSet rs = psmt.executeQuery(sql);
while (rs.next()) {
String dateString = rs.getString(1);
System.out.println("As String :"+ dateString);
}
con.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
private static Connection getConnection() {
Connection connection = null;
try {
Class.forName("oracle.jdbc.pool.OracleDataSource");
java.util.Properties info = new java.util.Properties();
info.put("user", "myuser");
info.put("password", "mypass");
info.put("oracle.jdbc.mapDateToTimestamp", "false");
connection = DriverManager.getConnection("jdbc:oracle:thin:@myserver:1521:myservicename", info);
}
catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
public static void main(String rgs[]) throws Exception {
DateIssue di = new DateIssue();
di.testDateOutput();
System.out.println("----------------------------------------------------");
}
使用 ojdbc6.jar(12.1.0.1.0) 输出为: As String :2013-11-12
使用 ojdbc6.jar(11.2.0.2.0) 输出为: As String :2013-11-12 11:10:09
Java版本:1.7
为什么 ojdbc6.jar(12.1.0.1.0) 中的行为会发生变化?如果我需要2013-11-12 11:10:09
使用 ojdbc6.jar(12.1.0.1.0) 格式的输出,我该怎么办?