当前位置:我的异常网» Java Web开发 » oracle安插时间为空
oracle安插时间为空
www.myexceptions.net 网友分享于:2014-04-13 浏览:9次
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;
}
public static void closePStmt(PreparedStatement pStmt)throws Exception{
if(pStmt!=null){
//try {
pStmt.close();
/*} catch (SQLException e) {
e.printStackTrace();
}*/
pStmt=null;
}
}
public static ResultSet executeQuery(PreparedStatement pStmt)throws Exception{
ResultSet rs = null;
//try {
rs = pStmt.executeQuery();
/*} catch (SQLException e) {
e.printStackTrace();
}*/
return rs;
}
public static void closeRs(ResultSet rs)throws Exception{
if(rs!=null){
//try {
rs.close();
rs=null;
/*} catch (SQLException e) {
e.printStackTrace();
}*/
}
}
public static Statement getStmt(Connection conn)throws Exception{
Statement stmt = null;
//try {
stmt=conn.createStatement();
/*} catch (SQLException e) {
e.printStackTrace();
}*/
return stmt;
}
public static void closeStmt(Statement stmt)throws Exception{
if(stmt!=null){
//try {
stmt.close();
/*} catch (SQLException e) {
e.printStackTrace();
}*/
stmt=null;
}
}
public static ResultSet exeQuery(Statement stmt,String sql)throws Exception{
ResultSet rs = null;
//try {
rs = stmt.executeQuery(sql);
/*} catch (SQLException e) {
e.printStackTrace();
}*/
return rs;
}
}
message代码如下:
package com.jll.util;
import java.sql.Blob;
import java.sql.Date;
//import java.sql.Timestamp;
public class MailMessage {
private String title;
private int receiver=0;
文章评论