0

I have code below

  List<Tbl> list = temp.query("select * from tbl WHERE DDMM = " + ddmm.format(date), new BeanPropertyRowMapper<Tbl>(Tbl.class));

Error

error: cannot find symbol
            List<Tbl> list = temp.query("select * from tbl WHERE DDMM = " + ddmm.format(date), new BeanPropertyRowMapper<Tbl>(Tbl.class));
  symbol:   class BeanPropertyRowMapper
John Joe
  • 12,412
  • 16
  • 70
  • 135

1 Answers1

0

BeanPropertyRowMapper requires the spring-jdbc JAR to be present on the classpath. To do this, you would either need to compile your program and manually include the spring-jdbc JAR on the classpath using command line flags. For more information, see Including jars in classpath on commandline (javac or apt). The spring-jdbc JAR can be found at Maven Repository. The catch is that JAR may require many more dependencies, which can be a hassle to get right.

I would suggest turning your project into a Maven project. For more information on creating a Maven project, see Maven in 5 Minutes. Once you Mavenize your project, add the following to your pom.xml, where ${spring.version} is the version of Spring you decide to use:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>${spring.version}</version>
</dependency>

Then, in the file that uses BeanPropertyRowMapper, add the following import statement:

import org.springframework.jdbc.core.BeanPropertyRowMapper;
Justin Albano
  • 3,809
  • 2
  • 24
  • 51
  • where can I get the jar file ? – John Joe Apr 07 '18 at 13:33
  • The JAR can be found at https://mvnrepository.com/artifact/org.springframework/spring-jdbc. You have to select version and on the page for that version, there is a line in the table called **Files**. Click the **JAR** link to download the JAR for that version. For example, the link for the `4.3.15.RELEASE` version is http://central.maven.org/maven2/org/springframework/spring-jdbc/4.3.15.RELEASE/spring-jdbc-4.3.15.RELEASE.jar. Again, I would highly suggest Mavenizing your project. Trying to manually do this is often called *dependency hell*--for good reason. – Justin Albano Apr 07 '18 at 13:36
  • Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/NonTransientDataAccessException Caused by: java.lang.NoClassDefFoundError: org/springframework/dao/NonTransientDataAccessException – John Joe Apr 07 '18 at 13:49
  • That is an indication that the `spring-jdbc` JAR requires another JAR to be on the classpath. If you look on the Maven Repository page for the `spring-jdbc` JAR (after you select a version), there is a section called **Compile Dependencies** that enumerates all of the compile-time dependencies for that JAR. **Again, I *highly* suggest you use some dependency management tool, like Maven or Gradle, to handle dependency resolution for you.** Doing it manually will be very painstaking. – Justin Albano Apr 07 '18 at 13:52
  • Thanks for you suggestion, I can't use Maven because this project was written by someone which was 10 years ago – John Joe Apr 07 '18 at 13:57
  • Not sure if this is an option, but I'll put it on the table: Can you take the existing code and put it within a Maven project structure. I.e. https://stackoverflow.com/questions/2449461/convert-existing-eclipse-project-to-maven-project. If not, there are sometimes what are called *fat JARs* that contain other JARs. You may be able to find a fat JAR for Spring (which contains the dependencies as well) and try compiling with that. Past that, you may have to just download the required JARs until the `NoClassDefFoundError`s stop and you successfully compile. – Justin Albano Apr 07 '18 at 14:03
  • I have removed the jar but still getting the same error message >< !!!! – John Joe Apr 07 '18 at 14:06
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/168458/discussion-between-justin-albano-and-john-joe). – Justin Albano Apr 07 '18 at 14:07