Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring JDBC giving error :"queryForObject(String, Object[], Class<String>) from the type JdbcTemplate refers to the missing type DataAccessException "

I have created a method in DAO:

public String getUserName(int userid){
    String sql="SELECT userName from UserDetail where userid=?";
    return jdbcTemplate.queryForObject(sql, new Object[]{userid}, String.class);
}

this line: jdbcTemplate.queryForObject(sql, new Object[]{userid}, String.class) is giving the following errors:

The method queryForObject(String, Object[], Class<String>) from the type JdbcTemplate refers to the missing type DataAccessException

Multiple markers at this line
- The type org.springframework.dao.DataAccessException cannot be resolved. It is indirectly referenced from required .class files
- The method queryForObject(String, Object[], Class<String>) from the type JdbcTemplate refers to the missing type 
 DataAccessException

I am using spring-jdbc 4.0.0 with mysql-connector 5.1.25, commons-dbcp-1.4 and commons-pool-1.6. Could you please tell me what am I mssing.

like image 967
ritesh Avatar asked Nov 22 '25 15:11

ritesh


2 Answers

Add spring-tx jar of your spring version to your classpath.

like image 69
Chris Avatar answered Nov 24 '25 05:11

Chris


DataAccessException is in org.springframework.transaction-3.0.0.RELEASE.jar -- include this jar in classpath.

like image 34
Vineel Avatar answered Nov 24 '25 05:11

Vineel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!