JavaEE MySQL数据库读取问题
代码如下: public List<Post> getTopicList(int id) throws Exception
{
PreparedStatement pst=null;
ResultSet rs=null;
String sql="select id,barId,title,text,pid,floor,hitnum,replynum,fromip,replyip,date_format(postDate,'%y-%m-%d %h:%i:%s') as pd,date_format(replyDate,'%y-%m-%d %h:%i:%s')as rd,author from post where barId=? and pid=0 order by replyDate desc";
try
{
pst=conn.prepareStatement(sql);
pst.setInt(1, id);
rs=pst.executeQuery();
return populatePost(rs);
}
finally
{
if (rs!=null) rs.close();
if (pst!=null) pst.close();
}
}
private List<Post> populatePost(ResultSet rs) throws Exception
{
List<Post> posts=new ArrayList<Post>();
while(rs.next())
{
Post post=new Post();
post.setId(rs.getInt("id"));
post.setBarId(rs.getInt("barId"));
post.setTitle(rs.getString("title"));
post.setText(rs.getString("text"));
post.setPid(rs.getInt("pid"));
post.setFloor(rs.getInt("floor"));
post.setHitnum(rs.getInt("hitnum"));
post.setReplynum(rs.getInt("replynum"));
post.setFromip(rs.getString("fromip"));
post.setReplyip(rs.getString("replyip"));
post.setPostDate(rs.getTimestamp("pd"));
post.setReplyDate(rs.getTimestamp("rd"));
post.setAuthor(rs.getString("author"));
posts.add(post);
}
return posts;
}
小弟为了让在JSP页面上时间长格式,写了上面的代码!但是运行后会提示Buffer overrun detected信息! 如果改成
select * from post where barId=? and pid=0 order by replyDate desc
并把pd 和re 改成数据库里的字段 可以正常运行! 但是在JSP页面上显示的时间格式不是想要的那种格式
post.setPostDate(rs.getTimestamp("pd"));
post.setReplyDate(rs.getTimestamp("rd"));
怎么样才能在JSP上显示yyyy-MM-dd HH:mm:ss 格式呢!