) from the type JdbcTemplate refers to the missing type DataAccessException "-6ren"> ) from the type JdbcTemplate refers to the missing type DataAccessException "-我在 DAO 中创建了一个方法: public String getUserName(int userid){ String sql="SELECT userName from UserDet-6ren">
gpt4 book ai didi

java - Spring JDBC 给出错误 :"queryForObject(String, Object[], Class) from the type JdbcTemplate refers to the missing type DataAccessException "

转载 作者:可可西里 更新时间:2023-11-01 07:49:48 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com