读写ORACLE日期格式字段时的两个问题

changleqy 2008-04-23 10:19:50
table1中有字段outdate(date),
其中有一条记录的值是'2008-4-1 14:12:00'
现在出现两个问题:
1,在修改页面中,先把原有值读出来,显示结果'2008-4-1 14:12:00.0',莫名其妙的多了个.0,读出来的代码如下
<input value="<%=outbean.getOutdate()%>" name="Outdate" type="text" id="Outdate" onFocus="setday(this)">

2,在执行修改时,提示错误“日期格式图片在转换整个输入字符串之前结束”,代码如下(错误在两个date字段上):

public int updateOutNotice(OutNoticeBean bean)
{
int result = 0;
Connection conn = DbConn.getConn();
PreparedStatement pst = null;
String sql = "update outnotice set shipperid=?,receiverid=?,driverid=?,"+
"currencyid=?,carnum=?,requireoutdate=to_date(?,'yyyy-mm-dd hh24:mi:ss'), "+
"outdate=to_date(?,'yyyy-mm-dd hh24:mi:ss'),state=?,operationid=?, "+
"remark=? "+
"where id=" + bean.getId();
try {
pst = conn.prepareStatement(sql);
pst.setInt(1, bean.getShipperid());
pst.setInt(2, bean.getReceiverid());
pst.setInt(3, bean.getDriverid());
pst.setInt(4, bean.getCurrencyid());
pst.setString(5, bean.getCarnum());
pst.setString(6, bean.getRequireoutdate());
pst.setString(7, bean.getOutdate());
pst.setString(8, bean.getState());
pst.setInt(9, bean.getOperationid());
pst.setString(10, bean.getRemark());
System.out.println(sql);
result = pst.executeUpdate();
} catch (SQLException ex) {
ex.printStackTrace();
} finally {

try {

pst.close();
pst = null;
conn.close();
conn = null;
} catch (SQLException e) {

e.printStackTrace();
}

}
return result;
}

...全文
132 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
J寻 2008-04-23
  • 打赏
  • 举报
回复
pst.setString(6, bean.getRequireoutdate()); 你这个地方获取到的是什么类型?
requireoutdate=to_date(?,'yyyy-mm-dd hh24:mi:ss')在这里加入的时候是不是类型有问题
你把运行后的sql语句贴出来看看
li_d_s 2008-04-23
  • 打赏
  • 举报
回复
关键是要看你怎么从数据库读出来的,.0是毫秒

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧