public void mSubstationUpdate(User user)
                        {      
                       DB db = new DB();
                    try {
                          String sql="update  T_SUBSTATION set SUPPORT_AREA=?,X0=?,Y0=?,X_NUMBER=?,Y_NUMBER=?,X0_J=?,Y0_J=?,COMMISSIONDATE=to_date(?,'yyyy-mm-dd'),UNDERCOMMISSIONDATE=to_date(?,'yyyy-mm-dd'),PLCOMMISSIONDATE=to_date(?,'yyyy-mm-dd'),DISCARDDATE=to_date(?,'yyyy-mm-dd') where PK_POWERSYSTEMRESOURCE=?";
  
                if (db.getAutoCommit())
                db.setAutoCommit(false);
                db.preparedStatement(sql);
db.setString(1, this.getSubstation_support());//直接从jsp页面取得数据 采用struts1的框架
db.setFloat(2, this.getSubstation_x0());
db.setFloat(3, this.getSubstation_y0());
db.setInt(4, this.getSubstation_xnumber());
db.setInt(5, this.getSubstation_ynumber());
db.setFloat(6, this.getSubstation_x0j());
db.setFloat(7, this.getSubstation_y0j());
db.setString(8, this.getCommissiondate());
db.setString(9, this.getUndercommissiondate());
db.setString(10, this.getPlcommissiondate());
db.setString(11, this.getDiscarddate());
db.setString(12, this.getSubstation_id());
System.out.println(sql);
db.executeUpdate();

db.commit();
LogUtil.logOperation(user, StaticValues.LOG_INSERT, getTable(), "Insert:" + toString());
}
catch (SQLException e)
{
e.printStackTrace();
LogUtil.logOperation(user, StaticValues.LOG_INSERT_ERR, getTable(), "Insert Error:" + toString());
}
finally
{
try
{
db.setAutoCommit(true);
}
catch (SQLException e)
{
}
db.closeDB();
db = null;

}
}
方法如上,我主要想知道我的sql语句里面的对日期格式的占位符设置是不是对呢?在eclispe下运行的时候没有报错但是就是一直卡住,不能把从jsp读取的String型的日期更新进去,我觉得是我的sql语句的问题,但是一直找不到原因,请教一下各位,谢谢了

解决方案 »

  1.   

    你可以用正则表达式来判断日期格式
    public  static boolean isDate(String str)
    {  

    //  日期正则判断
     Pattern p =
     Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))?$");
    //示例
     String s = "2003-02-29";
      System.out.println(s + " " + p.matcher(s).matches());
      return p.matcher(str).matches(); 
    }
      

  2.   

    如果是java代码,建议用java.util.Date类型处理?参数。