簡體   English   中英

Spring JDBC給出錯誤:“queryForObject(String,Object [],Class <String> )從類型JdbcTemplate引用缺少的類型DataAccessException“

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM