[英]Return generic type from Spring JdbcTemplate's queryForObject method
[英]Spring JDBC giving error :“queryForObject(String, Object[], Class<String>) from the type JdbcTemplate refers to the missing type DataAccessException ”
我在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版本添加到類路徑中。
DataAccessException位於org.springframework.transaction-3.0.0.RELEASE.jar中 - 在classpath中包含此jar。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.