mybatis执行sql异常,实在找不出问题出在哪了! 5C

配置文件



















映射文件


select * from USERINFO where USERNAME=#{username} and PWD=#{pwd}


映射接口
public interface UserInfoMaper {
public UserInfoBean selectuser(UserInfoBean userInfoBean);
}

实体类
public class UserInfoBean {
private String name;
private String username;
private String pwd;

public UserInfoBean(String name, String username, String pwd) {
    this.name = name;
    this.username = username;
    this.pwd = pwd;
}

public UserInfoBean() {

}

public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getUsername() {
    return username;
}
public void setUsername(String username) {
    this.username = username;
}
public String getPwd() {
    return pwd;
}
public void setPwd(String pwd) {
    this.pwd = pwd;
}

}
测试类
public class MainTest {
private static UserInfoBean userentity;
public static void main(String[] args) {
SqlSession sqlSession = MybatisUtil.getSqlSession();
System.out.println(sqlSession);
UserInfoBean userInfoBean = new UserInfoBean();
userInfoBean.setUsername("admin");
userInfoBean.setPwd("123456");
UserInfoMaper userInfoMaper = sqlSession.getMapper(UserInfoMaper.class);
userentity =userInfoMaper.selectuser(userInfoBean);
}
}
当执行到userInfoMaper.selectuser(userInfoBean)异常
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: oracle.jdbc.OracleDriver

The error may exist in SQLMaper.xml

The error may involve org.great.maper.UserInfoMaper.selectuser

The error occurred while executing a query

Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: oracle.jdbc.OracleDriver

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:62)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
at com.sun.proxy.$Proxy0.selectuser(Unknown Source)
at org.great.main.MainTest.main(MainTest.java:17)

Caused by: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: oracle.jdbc.OracleDriver
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:211)
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:190)
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:186)
at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:88)
at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:373)
at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:82)
at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:131)
at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:58)
at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:271)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:69)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:56)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
... 6 more

8个回答

异常已经很明显了,jdbc配置错误,driverClassName=oracle.jdbc.driver.OracleDriver,不是oracle.jdbc.OracleDriver

这应该是mybatis的一个bug,编译错误,没有报异常抛出来。

重新编译一遍,在编译之前 先把配置文件里变量大小写统一

Cannot find class: oracle.jdbc.OracleDriver ,先查看jdbc配置

缺少oracle.jdbc.OracleDriver这个jar包

缺少jdbc驱动jar包

这个是报的是数据库驱动包的异常信息,不是sql映射问题,可以先检查一下,数据库配置信息是否正确,执行一遍,不行的话,重新编译一下,或重新导入数据库驱动包再试试

你的驱动配置文件应该出错了 去检查配置文件

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问