当前位置: 代码迷 >> J2EE >> 提示:You have an error in your SQL syntax,该怎么处理
  详细解决方案

提示:You have an error in your SQL syntax,该怎么处理

热度:418   发布时间:2016-04-22 02:30:37.0
提示:You have an error in your SQL syntax
Java code
/**     * 添加操作记录     */    public Statistics saveStatistics(Integer status, List<BlogStatus> batchProcess) {        Statistics stat = new Statistics();        Article article = getArticle();        User user = getLoggedOnUser();        stat.setType(2);//文章        stat.setUserId(user.getId());        Date date = new Date();        SimpleDateFormat dateformat=new SimpleDateFormat("yyyy-MM-dd");        dateformat.format(date);        stat.setStatisticsTime(date);        if(status != null) {            switch (status) {            case 0://重申                stat.setDescribe(user.getUsername() + "重申了"+article.getCommUser().getUserName()+"发表的文章" + article.getTitle());                break;            case 1://通过                stat.setDescribe(user.getUsername() +article.getCommUser().getUserName()); //article.getTitle()                break;            case 2://屏蔽                stat.setDescribe(user.getUsername() + "屏蔽了"+article.getCommUser().getUserName()+"发表的文章" + article.getTitle());                break;            case 3://删除                stat.setDescribe(user.getUsername() + "删除了"+article.getCommUser().getUserName()+"发表的文章" + article.getTitle());                break;            }        }        if(batchProcess != null) {            stat.setDescribe(user.getUsername() + "处理了"+article.getCommUser().getUserName()+"发表的文章" + article.getTitle());        }        [color=#FF0000statisticsManager.save(stat);][/color] //这里执行走不了        this.saveStatisticsDesc(stat,article);        return stat;    }


错误信息如下:

Hibernate: insert into ibokee_statistics (describe, statisticsTime, type, userId) values (?, ?, ?, ?)
WARN ["http-bio-8080"-exec-9] JDBCExceptionReporter.logExceptions(100) | SQL Error: 1064, SQLState: 42000
ERROR ["http-bio-8080"-exec-9] JDBCExceptionReporter.logExceptions(101) | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'describe, statisticsTime, type, userId) values ('adminzhender', '2011-11-25 10:4' at line 1


------解决方案--------------------
statisticsTime是日期類型吧,可你傳了一個字符串
------解决方案--------------------
我説你數據庫的字段,不是代碼
------解决方案--------------------
反了。。。。。應該是你數據庫字段和你代碼類型不對
------解决方案--------------------
SQL错误。 你的时间错了。时间要转换的。
------解决方案--------------------
Java code
            SimpleDateFormat dateformat=new SimpleDateFormat("yyyy-MM-dd");            Date date = new Date();            date = dateformat.parse(dateformat.format(date));这样试试。。。
  相关解决方案