我在 DAO 中创建了一个方法:
public String getUserName(int userid){
String sql="SELECT userName from UserDetail where userid=?";
return jdbcTemplate.queryForObject(sql, new Object[]{userid}, String.class);
}
此行:jdbcTemplate.queryForObject(sql, new Object[]{userid}, String.class) 出现以下错误:
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
我将 spring-jdbc 4.0.0 与 mysql-connector 5.1.25、commons-dbcp-1.4 和 commons-pool-1.6 一起使用。你能告诉我我在说什么吗?
最佳答案
添加spring-tx jar将你的 spring 版本添加到你的类路径中。
关于java - Spring JDBC 给出错误 :"queryForObject(String, Object[], Class<String>) from the type JdbcTemplate refers to the missing type DataAccessException ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17008764/