3

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.

4

2 回答 2

7

将你的 spring 版本的spring-tx jar添加到你的类路径中。

于 2013-06-09T10:46:20.517 回答
1

DataAccessException 在 org.springframework.transaction-3.0.0.RELEASE.jar 中——在类路径中包含这个 jar。

于 2016-08-25T12:44:48.477 回答