日期:2014-05-20  浏览次数:20696 次

读写ORACLE日期格式字段时的两个问题
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;
  }



------解决方案--------------------
关键是要看你怎么从数据库读出来的,.0是毫秒
------解决方案--------------------
pst.setString(6, bean.getRequireoutdate()); 你这个地方获取到的是什么类型?
requireoutdate=to_date(?,'yyyy-mm-dd hh24:mi:ss')在这里加入的时候是不是类型有问题
你把运行后的sql语句贴出来看看