org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback

Issue:


HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [INSERT INTO project (id, name, start_date, end_date, description, bash_path, def_init) VALUES (1, ?, ?, ?, ?, 'NO')]; Parameter index out of range (5 > number of parameters, which is 4).; nested exception is java.sql.SQLException: Parameter index out of range (5 > number of parameters, which is 4).

type Exception report
message Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [INSERT INTO project (id, name, start_date, end_date, description, bash_path, def_init) VALUES (1, ?, ?, ?, ?, 'NO')]; Parameter index out of range (5 > number of parameters, which is 4).; nested exception is java.sql.SQLException: Parameter index out of range (5 > number of parameters, which is 4).
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.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [INSERT INTO project (id, name, start_date, end_date, description, bash_path, def_init) VALUES (1, ?, ?, ?, ?, 'NO')]; Parameter index out of range (5 > number of parameters, which is 4).; nested exception is java.sql.SQLException: Parameter index out of range (5 > number of parameters, which is 4).
 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
 org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
 org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [INSERT INTO project (id, name, start_date, end_date, description, bash_path, def_init) VALUES (1, ?, ?, ?, ?, 'NO')]; Parameter index out of range (5 > number of parameters, which is 4).; nested exception is java.sql.SQLException: Parameter index out of range (5 > number of parameters, which is 4).
 org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:106)
 org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
 org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
 org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
 org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:660)
 org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:909)
 org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:970)
 org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:980)
 com.tutorialbyexample.dao.ProjectDAOImpl.save(ProjectDAOImpl.java:36)
 com.tutorialbyexample.controller.ProjectController.saveProject(ProjectController.java:59)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 java.lang.reflect.Method.invoke(Method.java:498)
 org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
 org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
 org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
 org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
 org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
 org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.sql.SQLException: Parameter index out of range (5 > number of parameters, which is 4).
 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
 com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3688)
 com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3670)
 com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:4491)
 org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:391)
 org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:235)
 org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:166)
 org.springframework.jdbc.core.ArgumentPreparedStatementSetter.doSetValue(ArgumentPreparedStatementSetter.java:66)
 org.springframework.jdbc.core.ArgumentPreparedStatementSetter.setValues(ArgumentPreparedStatementSetter.java:47)
 org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:914)
 org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:909)
 org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:644)
 org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:909)
 org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:970)
 org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:980)
 com.tutorialbyexample.dao.ProjectDAOImpl.save(ProjectDAOImpl.java:36)
 com.tutorialbyexample.controller.ProjectController.saveProject(ProjectController.java:59)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 java.lang.reflect.Method.invoke(Method.java:498)
 org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
 org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
 org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
 org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
 org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
 org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.5.4 logs.

Apache Tomcat/8.5.4


Solutions:
Add the aditional ? in insert statement:

INSERT INTO project (id, name, start_date, end_date, description, bash_path, def_init) VALUES (1, ?, ?, ?, ?,?, 'NO')

11 comments:

  1. terraform-aws-beginner-advanced-level-full-course

    Welcome and in "Terraform Full Course Beginner to Advanced Level" course you are going to learn as mentioned points in details:
    1. Terraform Introduction
    1.1 Terraform Architecture
    2. Terraform Installation In Windows 10
    3. Terraform Pros and Cons
    4. Terraform Provider & AWS Access and Secret Key
    5. Terraform Input Variables
    6. Terraform Resource
    7. Terraform Data Source
    8. Terraform Output Values
    9. Terraform Commands
    9.1 Terraform Commands Add Change and Destroy
    10. Terraform Instance
    11. Terraform VPC, Subnet, IG, NGW, Security Group, and Instance
    12. Terraform VPC, Subnet, IG, NGW, Security Group, Instance and Route 53
    13. Terraform Modules 901 & 902
    13.1. Terraform Modules 903
    14. Terraform S3 Bucket
    15. Terraform State Local and Remote
    16. Terraform Import (Reverse Engineering)
    17. Terraform Multi-Envs and Multi-Region
    18. Terraform 1401 Count
    19. Terraform 1402 For_Each

    Other full courses links:
    Terraform and AWS Full Course Terraform and AWS Full Course
    Python Programming Full Course Python Programming Full Course
    Sonatype Nexus Repository Manager Full Course Sonatype Nexus Repository Manager Full Course
    Apache Maven Full Course Apache Maven Full Course
    Git Full Course Git Full Course

    ReplyDelete