sqlserver日期转换错误:Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]

今天用java开发sqlserver2008数据库时,将结果存入bean时报错Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff],后来发现,是数据库字段格式不对,日期格式应该使用datetiem,如果实在是用date类型,需要将其结果读取存入map集合中,在java前台通过dateformat转换后存入bean中即可。

 

如果服务器是CENTOS系统,则服务器的日期格式与数据库sqlserver的日期格式是不对应的,设计数据库时需要将datetime类型改为varchar类型,bean中对应的也需要改为String类型,保存时,将数据通过DataFormat转换

 /*属性 */

    private String ydid;  //编码

    private RsEmployee jgbm;  //人员编码

    private String ydlxbm;  //异动类型编码

    private String ydxq;  //异动学期

    private String ydsj;  //异动时间

    private String ydsm;  //异动说明

    private int lrr;  //录入人

    private String lrsj;  //录入时间

    private int buse;  //是否可用 0:不好用 1:可用

    private int school_id;

 

 

 

public String addSaveRSYd() throws Exception {

        

        //rsEmployeeyd.setYdid(0);

        

        HttpSession session = request.getSession();

        

        int school_id = Integer.parseInt(session.getAttribute("schoolid").toString()); 

        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        Date now = new Date();

        rsEmployeeyd.setJgbm(rsEmployeeyd.getJgbm());

        rsEmployeeyd.setYdlxbm(rsEmployeeyd.getYdlxbm());

        rsEmployeeyd.setLrsj(format.format(now));

        rsEmployeeyd.setYdsj(format.format(rsEmployeeyd.getYdsj()));

        rsEmployeeyd.setYdsm(rsEmployeeyd.getYdsm());

        rsEmployeeyd.setBuse(1);

        rsEmployeeyd.setSchool_id(school_id);

        rsEmployeeydService.addInfo(rsEmployeeyd);

        

        return SUCCESS;

        

    }

 

 

 

你可能感兴趣的:(yyyy-mm-dd)