SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public int addThreads(Threads threads) {
int num=0;
String sql="insert into threads(fid,author,authorid,subject,dateline,lastPost,lastPoster,views,replies,displayOrder,highLight,digest,attachment,moderated) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
this.openConn();
try {
pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,threads.getFid());
pstmt.setString(2, threads.getAuthor());
pstmt.setInt(3, threads.getAuthorid());
pstmt.setString(4,threads.getSubject());
pstmt.setString(5,df.format(threads.getDateline()));
pstmt.setString(6,df.format(threads.getLastPost()));
pstmt.setString(7,threads.getLastPoster());
pstmt.setInt(8,threads.getViews());
pstmt.setInt(9,threads.getReplies());
pstmt.setByte(10,threads.getDisplayOrder());
pstmt.setByte(11,threads.getHighLight());
pstmt.setByte(12,threads.getDigest());
pstmt.setByte(13,threads.getAttachment());
pstmt.setByte(14,threads.getModerated());
pstmt.executeUpdate();
pstmt=conn.prepareStatement("select @@identity as id");
rs=pstmt.executeQuery();
if(rs.next()){
num=rs.getInt("id");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.closeAll();
}
return num;
}
action中
threads.setDateline(new Date());
threads.setLastPost(new Date());
我在实现类中打印也日期,也精确到时分秒,但插入数据库中时分秒就变为00:00:00了,
我给它一个精确到时分秒的字符串,插入到数据库中的也变为00:00:00,为什么啊?帮帮忙吧?
public int addThreads(Threads threads) {
int num=0;
String sql="insert into threads(fid,author,authorid,subject,dateline,lastPost,lastPoster,views,replies,displayOrder,highLight,digest,attachment,moderated) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
this.openConn();
try {
pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,threads.getFid());
pstmt.setString(2, threads.getAuthor());
pstmt.setInt(3, threads.getAuthorid());
pstmt.setString(4,threads.getSubject());
pstmt.setString(5,df.format(threads.getDateline()));
pstmt.setString(6,df.format(threads.getLastPost()));
pstmt.setString(7,threads.getLastPoster());
pstmt.setInt(8,threads.getViews());
pstmt.setInt(9,threads.getReplies());
pstmt.setByte(10,threads.getDisplayOrder());
pstmt.setByte(11,threads.getHighLight());
pstmt.setByte(12,threads.getDigest());
pstmt.setByte(13,threads.getAttachment());
pstmt.setByte(14,threads.getModerated());
pstmt.executeUpdate();
pstmt=conn.prepareStatement("select @@identity as id");
rs=pstmt.executeQuery();
if(rs.next()){
num=rs.getInt("id");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.closeAll();
}
return num;
}
action中
threads.setDateline(new Date());
threads.setLastPost(new Date());
我在实现类中打印也日期,也精确到时分秒,但插入数据库中时分秒就变为00:00:00了,
我给它一个精确到时分秒的字符串,插入到数据库中的也变为00:00:00,为什么啊?帮帮忙吧?
在插入语句中,日期那个字段,直接写成now(),就不要用?点位了.读取也一样,直接出来就是yyyy-mm-dd hh:mm:ss
我记得当初我是to_date 了。