Reputation: 1358
I am trying to hit the database using spring JdbcTemplate... I have added the required dependency spring-jdbc in pom.xml.. the required jar is successfully added to eclipse library...I can see it in maven dependency folder in eclipse...
But still, I am facing an issue with importing the class JdbcTemplate & hence unable to proceed further...
I am getting this error - JdbcTemplate cannot be resolved to a type
I had created a new project again in the eclipse... still having the same error....
Code :
import java.util.List;
import javax.sql.DataSource;
import com.wocs.services.inventory.model.Customer;
public class CustomerDAO implements CustomeryDAOIface{
private DataSource dataSource;
private JdbcTemplate jdbcTemplateObject;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplateObject = new JdbcTemplate(dataSource);
}
public List<Customer> getManufacturers() {
String sql = "SELECT * FROM Customer";
List<Customer> customers =
getJdbcTemplate().query(sql,
new BeanPropeMtyRowMapper(Customer.class));
return customers;
}
}
system & application configuration: OS: ubuntu 16.0.4 spring version - 5.0.3 tomcat 9 (also tried alternative tomcat 7) jdk 91. (tried alternative 1.7, 1.8 too) Eclipse Oxygen 3
It will be very helpful for me if any one can give me the solution...
Upvotes: 2
Views: 13252
Reputation: 23
Add this dependency to your pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
Then update your project
(right-click on the project)->Maven->Update project
Make sure you have an internet connection while updating.
It should resolve the error.
Upvotes: 1
Reputation: 506
Upvotes: 2