oracle插入时间为空
oracle里面有一张表,设计如下
message表:
create table message (messageID number(11) constraint message_primarykey primary key,
mcontext blob ,
sendtime date,
senduser number(7) references mailuser(userID),
receiveuser number(7) references mailuser(userID),
mtitle varchar2(20));
我用jsp在浏览器中输入,放到数据库里,用的是struts2,代码如下:
action里的方法代码:
try{
int id = (Integer)session.getAttribute("ID");
String sql="insert into message values(null,?,?,?,?,?)";
pStmt=Driver.getPStmt(conn, sql);
pStmt.setBlob(1, message.getContent());
pStmt.setDate(2, message.getSendTime());
pStmt.setInt(3, id);
pStmt.setInt(4, message.getReceiver());
pStmt.setString(5, message.getTitle());
Driver.executeQuery(pStmt);
} catch (Exception e) {
e.printStackTrace();
return "fail";
} finally{
try {
Driver.closeRs(rs);
Driver.closePStmt(pStmt);
Driver.closeConn(conn);
} catch (Exception e) {
e.printStackTrace();
}
}
return "success";
}
其中Driver只是实现了连接数据库的部分,代码如下:
package com.jll.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
public class Driver {
public static Connection conn = null;
public static ResultSet rs = null;
private static String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
static String userName1 = "scott";
static String password1 = "tiger";
public static Connection getconn()throws Exception{
// try {
Class.forName("oracle.jdbc.OracleDriver");
conn=DriverManager.getConnection(url,userName1,password1);
/*} catch (
ClassNotFoundException e) {
e.printStackTrace();
}catch (
SQLException e) {
e.printStackTrace();
}*/
return conn;
}
public static void closeConn(Connection conn) throws Exception{
if(conn!=null){
// try {
conn.close();
conn =null;
/*} catch (SQLException e) {
e.printStackTrace();
}*/
}
}
// public static void setStmt(Connection conn,Statement stmt){
// Statement stmt = null;
// stmt=conn.createStatement();
// }
public static PreparedStatement getPStmt(Connection conn,String sql)throws Exception{
PreparedStatement pStmt = null;
// try {
pStmt=conn.prepareStatement(sql);
/*} catch (SQLException e) {
e.printStackTrace();
}*/
return pStmt;<