title: Spring JDBC -- bad SQL grammar
body: <p>I'm working my way through a Spring tutorial, and I'm having a problem in the JDBC section.  The code was copied directly from the tutorial itself, and several calls to the database ran correctly before the one that failed.  Can anyone help me?  Here is my error trace.</p>
  
  <pre><code>Jul 31, 2012 9:40:03 PM org.springframework.jdbc.core.metadata.GenericCallMetaDataProvider processProcedureColumns
  WARNING: Error while retrieving metadata for procedure columns: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: FUNCTION getrecord does not exist
  Jul 31, 2012 9:40:03 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  INFO: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
  Jul 31, 2012 9:40:03 PM org.springframework.jdbc.support.SQLErrorCodesFactory &lt;init&gt;
  INFO: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]    Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar [{call getrecord()}]; nested exception is com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: FUNCTION getrecord does not exist
          at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:98)
          at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
          at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
          at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
          at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:969)
          at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1003)
          at org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:391)
          at org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:354)
          at org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:181)
          at com.tutorialspoint.StudentJDBCTemplate.getStudent(StudentJDBCTemplate.java:32)
          at com.tutorialspoint.MainApp.main(MainApp.java:29)
      Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: FUNCTION getrecord does not exist
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
          at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
          at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
          at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
          at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
          at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
          at com.mysql.jdbc.Statement.executeQuery(Statement.java:1232)
          at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1607)
          at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:4034)
          at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:709)
          at com.mysql.jdbc.CallableStatement.&lt;init&gt;(CallableStatement.java:513)
          at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4583)
          at com.mysql.jdbc.Connection.prepareCall(Connection.java:4657)
          at com.mysql.jdbc.Connection.prepareCall(Connection.java:4631)
          at org.springframework.jdbc.core.CallableStatementCreatorFactory$CallableStatementCreatorImpl.createCallableStatement(CallableStatementCreatorFactory.java:167)
          at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:947)
          ... 6 more
  </code></pre>
  
  <p>Here is the section of my main application where the problem occurs, and I've marked the line in question.</p>
  
  <pre><code>    System.out.println("----Listing Record with ID = 2 -----");
          // Error occurs in next line
      Student student = studentJDBCTemplate.getStudent(2);
      System.out.print("ID : " + student.getId());
      System.out.print(", Name : " + student.getName());
      System.out.println(", Age : " + student.getAge());
  </code></pre>
  
  <p>StudentJDBCTemplate has these two variables.</p>
  
  <pre><code>private DataSource dataSource;
  private SimpleJdbcCall jdbcCall;
  </code></pre>
  
  <p>StudentJDCBTemplate sets the data source like this, and this may be the genesis of the problem, since I cannot figure out what getRecord refers to.</p>
  
  <pre><code>public void setDataSource(DataSource dataSource) {
      this.dataSource = dataSource;
      this.jdbcCall = new SimpleJdbcCall(dataSource)
              .withProcedureName("getRecord");
  }
  </code></pre>
  
  <p>The problem occurs in this method of StudentJDBCTemplate.</p>
  
  <pre><code>public Student getStudent(Integer id) {
      SqlParameterSource in = new MapSqlParameterSource().addValue("in_id",
              id);
      Map&lt;String, Object&gt; out = jdbcCall.execute(in);
      Student student = new Student();
      student.setId(id);
      student.setName((String) out.get("out_name"));
      student.setAge((Integer) out.get("out_age"));
      return student;
  }
  </code></pre>
  
  <p>Here is my Beans.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd "&gt; &lt;!-- Initialization for data source --&gt;
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/TEST" /&gt;
          &lt;property name="username" value="root" /&gt;
          &lt;property name="password" value="password" /&gt;
      &lt;/bean&gt; &lt;!-- Definition for studentJDBCTemplate bean --&gt;
      &lt;bean id="studentJDBCTemplate" class="com.tutorialspoint.StudentJDBCTemplate"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>For what it's worth, here is my Student class.</p>
  
  <pre><code>package com.tutorialspoint;
  
  public class Student {
      private Integer age;
      private String name;
      private Integer id;
  
      public void setAge(Integer age) {
          this.age = age;
      }
  
      public Integer getAge() {
          return age;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getName() {
          return name;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public Integer getId() {
          return id;
      }
  }
  </code></pre>