嵌套异常是 java.sql.SQLTransactionRollbackException:

概述


我制作了一个控制器,我通过自动装配传递 Dao 并使用 jdbctemplate 执行查询。


控制器调用 dao 中的方法从数据库中检索一个表。


代码


控制器


@Controller  

public class ManagerRoles {

    @Autowired  

    EmployeeDao dao;

    @RequestMapping("getEmployeeSchedule/{empID}")

    public ModelAndView employeeData(@PathVariable("empID")int empID,HttpServletRequest req,HttpServletResponse res,ModelMap model){

        long millis=System.currentTimeMillis();  

        Date dateStart = new Date(millis); 

        Date dateFinal = new Date(dateStart.getYear(),dateStart.getMonth(),dateStart.getDate()+30);

        System.out.println(dateStart);

        System.out.println(dateFinal);

        List<EmployeeHolidays> holidayList = dao.retrieveHolidays(dateStart, dateFinal);

        if(holidayList!=null){

        model.put("holidayList",holidayList);

        }

        System.out.println(holidayList);

        return null;

    }

}


问题是当我尝试运行 webapp 时,当我尝试检索表数据时出现以下错误。


类型异常报告


消息请求处理失败;嵌套异常是 org.springframework.dao.ConcurrencyFailureException: StatementCallback; SQL [SELECT * FROM HOLIDAYS WHERE DATE >= ? 和日期 <= ? ]; 当前语句的至少一个参数未初始化。嵌套异常是 java.sql.SQLTransactionRollbackException:至少当前语句的一个参数未初始化。


说明 服务器遇到了阻止其完成请求的意外情况。


例外


org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 org.springframework.dao.ConcurrencyFailureException: StatementCallback; SQL [SELECT * FROM HOLIDAYS WHERE DATE >= ? 和日期 <= ? ]; 当前语句的至少一个参数未初始化。嵌套异常是 java.sql.SQLTransactionRollbackException:至少当前语句的一个参数未初始化。org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) javax.servlet.http.HttpServlet.service(HttpServlet.java: 622)org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

http://img1.mukewang.com/6131e5340001e5ef18600855.jpg

我检查了我传递的参数,它们都有值。

我似乎没有找到问题的根源。谁能帮我这个?



蛊毒传说
浏览 726回答 1
1回答

忽然笑

您忘记将parametersas添加arguments到查询方法中,请看这里:public List<EmployeeHolidays> retrieveHolidays(Date startDate,Date endDate){&nbsp; &nbsp; &nbsp; &nbsp; String sql = "SELECT * FROM HOLIDAYS WHERE DATE >= ? AND DATE <= ? ";&nbsp; &nbsp; &nbsp; &nbsp; List<EmployeeHolidays> list = template.query(sql ,new Object[] { startDate, endDate} //add thisnew RowMapper<EmployeeHolidays>(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public EmployeeHolidays mapRow(ResultSet rs,int rownumber) throws SQLException{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EmployeeHolidays e = new EmployeeHolidays();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.setDate(rs.getDate(1));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.setReason(rs.getString(2));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.setStatus(rs.getString(3));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return e;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; return list;&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java