0

I'm able to successfully connect to a MySQL database with SpringMVC and JDBC, I can run queries and updates no problem, until I try to add named parameters. Any named parameter and I get the following exception:

nested exception is java.lang.NoSuchMethodError: org.springframework.jdbc.core.StatementCreatorUtils.javaTypeToSqlParameterType
(Ljava/lang/Class;)I] with root cause

I iterated through the params and verified that the id and values are correct and match the text I use when I'm coding the text directly into the query.

Thanks for any help debugging this:

Code that fails:

public boolean create(Beer beer) {
    System.out.println("Creating beer in Dao");
    System.out.println(beer);
    BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(beer);
    return jdbc.update("insert into beer (beer_name) values (:name)", params) == 1;

}

code that works:

public boolean create(Beer beer) {
    System.out.println("Creating beer in Dao");
    System.out.println(beer);
    BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(beer);
    return jdbc.update("insert into beer (beer_name) values (\"honey porter\")", params) == 1;

}
Bosko Mijin
  • 3,287
  • 3
  • 32
  • 45
paniclater
  • 903
  • 1
  • 12
  • 18
  • 2
    The usual cause for NoSuchMethodErrors is that you compiled against one version of a library, but are running against another version. Also take care that you don't have multiple versions of a library on your classpath, because you may load old classes from the older library, but the few classes that were added in the new version you'll load from the newer library. – Erwin Bolwidt May 09 '14 at 15:30
  • Since the error comes from org.springframework.jdbc.core.StatementCreatorUtils.javaTypeToSqlParameterType does that mean I'm pretty safe assuming that there is a conflicting older version of spring-jdbc and if so, how can I try to resolve this? I don't see more than one version of jdbc in my pom.xml. – paniclater May 09 '14 at 15:44
  • I believe that there is still a spring-all jar in addition to the individual jars - they overlap, the all-jar includes the classes of the more specific jars (at least it used to be like that, I haven't used the big jar for a long time). Maybe you're using the all-jar of a different version than the jdbc jar? – Erwin Bolwidt May 09 '14 at 15:48
  • I'm seeing now that the default setup of the Spring Tool Suite project has my org.springframework-version at 3.1.1.RELEASE and my spring-jdbc is set to 4.0.3. I'm going to try reconciling the versions and see if that works. – paniclater May 09 '14 at 15:52
  • Unfortunately, I tried setting the dependencies to the same release and I am still getting the same error. – paniclater May 09 '14 at 16:32
  • I went ahead and removed all maven dependencies, deleted all my maven dependencies and then added them back in one by one until there were no more dependency issues. No dice. Back to the drawing board. – paniclater May 09 '14 at 18:56

0 Answers0