【问题标题】:inserting values using multiple actions in same controller and same jdbc template query在同一控制器和同一 jdbc 模板查询中使用多个操作插入值
【发布时间】:2017-09-08 05:00:19
【问题描述】:

错误

HTTP Status 500 - Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [UPDATE rd SET LabNo=?,Category =?,ProductCode=?,StageCode=?,BatchNo=?,Analysis=?,RequestBy=?, Date1=?,ReceivedBy=?,Date2=?,RawNo=?,Test=?,Result=?,SubmittedBy=?,Date3=?, WHERE ArNo=?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'WHERE ArNo='2015-06-07 00:00:00'' at line 1


type Exception report

message Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [UPDATE rd SET LabNo=?,Category =?,ProductCode=?,StageCode=?,BatchNo=?,Analysis=?,RequestBy=?, Date1=?,ReceivedBy=?,Date2=?,RawNo=?,Test=?,Result=?,SubmittedBy=?,Date3=?, WHERE ArNo=?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'WHERE ArNo='2015-06-07 00:00:00'' at line 1

description The server encountered an internal error that prevented it from fulfilling this request.

exception 
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [UPDATE rd SET LabNo=?,Category =?,ProductCode=?,StageCode=?,BatchNo=?,Analysis=?,RequestBy=?, Date1=?,ReceivedBy=?,Date2=?,RawNo=?,Test=?,Result=?,SubmittedBy=?,Date3=?, WHERE ArNo=?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'WHERE ArNo='2015-06-07 00:00:00'' at line 1
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)



root cause 
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [UPDATE rd SET LabNo=?,Category =?,ProductCode=?,StageCode=?,BatchNo=?,Analysis=?,RequestBy=?, Date1=?,ReceivedBy=?,Date2=?,RawNo=?,Test=?,Result=?,SubmittedBy=?,Date3=?, WHERE ArNo=?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'WHERE ArNo='2015-06-07 00:00:00'' at line 1
    org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233)
    org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:603)
    org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:812)
    org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:868)
    org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:876)
    com.elakk.dao.EmployeDaoImpl.saveorupdate(EmployeDaoImpl.java:128)
    com.elakk.service.EmployeServiceImpl.saveorupdate(EmployeServiceImpl.java:32)
    com.elakk.controller.EmployeeController.registerprocess(EmployeeController.java:53)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

代码

public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping(value = "rd", method = RequestMethod.GET)
    public String showrdPage(HttpSession session) {
        session.setAttribute("RD", "rd");
        System.out.println("invoking rd page");
        return "rd";
    }

    @RequestMapping(value = "rdProcess", method = RequestMethod.POST)
    public String registerprocess(HttpServletRequest request, HttpServletResponse response,
            @ModelAttribute("rd") RD rd) {
        @SuppressWarnings("unused")
        String operation = request.getParameter("rd.getOperation");
        System.out.println("bname......................" + rd.getOperation());
        System.out.println("test............");
        if (rd.getOperation() == "save") {
            rd.setStatus("RDSave");
        } else if (rd.getOperation() == "update") {
            rd.setStatus("RDSubmit");
        }


            System.out.println("Test registerProcess");
            rd = employeeService.saveorupdate(rd);

        return "rd";
    }

}

【问题讨论】:

    标签: java spring jdbc


    【解决方案1】:

    更正这段代码

    Date3=?, WHERE 
    

    这里不应该有逗号

    【讨论】:

    • 当我编译这段代码只是插入数据库时​​,我想更新数据库中的相同数据。
    • 是的......由于我在回答中修复的错误,它引发了异常
    • 所以阅读下一个错误并修复无法将值“wer”从类型“java.lang.String”转换为类型“int”;嵌套异常是 java.lang.NumberFormatException: For input string: "wer"] - 请接受我的回答
    • @Override public boolean isValidARNumber(String arNumber){ boolean arNotExist = false; Object[] loginObj = new Object[]{arNumber};整数列表数据 = 0; String sql = "SELECT COUNT(*) from RD where ARNO = ?"; if(jdbcTemplate != null){ listData = jdbcTemplate.queryForInt(sql, loginObj); } if(listData != 0){ arNotExist = true; } 返回 arNotExist; } 请帮助在上面的控制器方法中更新这个
    猜你喜欢
    • 1970-01-01
    • 2016-09-19
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多