0
這是我使用插入日期到數據庫的方法:插入日期和分鐘
public void insertLog(Connection con, UserLogs userLogs) throws SQLException{
PreparedStatement pstmt = null;
ResultSet rs= null;
String SQL = "insert into logs values(?,to_date(sysdate,'DD/MM/YYYY HH24:MI'))";
try {
pstmt = con.prepareStatement(SQL);
pstmt.setInt(1, userLogs.getUserId());
rs = pstmt.executeQuery();
} catch (SQLException e) {
System.out.println(e);
}finally{
if(rs!=null){
rs.close();
}
if(pstmt!=null){
pstmt.close();
}
}
}
現在有一個問題...它成功地插入,但是當我做一個SELECT * FROM記錄小時和分鐘顯示爲00:00(使用Oracle),所以我的猜測是,我必須改變這種格式的會話:爲了
alter session set nls_date_format='DD/MM/YYYY HH24:MI';
的顯示器正常工作。我怎樣才能發送這個SQL,然後插入相同的executeQuery?
@JoeW oracle 11g – Alpha2k 2014-09-24 19:54:51
'to_date(sysdate,...)'完全沒用。 'sysdate'已經是'日期'了,不需要將它轉換爲一個。 – 2014-09-24 20:15:31