org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class:
### The error may exist in mybatis\role.xml
### The error may involve jdbc.mapper.RoleMapper.countRoles
### The error occurred while executing a query
### Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class:
在學習最基本的Mybatis配置運行時報出了這樣一個錯誤java
(1)一開始的時候看到 Cause: java.sql.SQLException: 當機立斷以爲是sql語句寫錯了,發現確實寫錯了,反覆改了3次,運行仍然報這個錯,反覆檢查了下sql語句,確信沒有問題了,很奇怪爲何仍是報這個錯。mysql
(2)再次看了下報錯,後面還有半句話 Error setting driver on UnpooledDataSource.Cause: java.lang.ClassNotFoundException: Cannot find class: 意思是沒有成功加載driver驅動。而後是爲何沒成功加載,緣由是沒有找到類,因而去查看了下配置文件sql
發現了以下的一幕,driver的值竟然是空的,崩潰。緣由處於此處。apache
<dataSource type="POOLED">
<property name="driver" value=""/>
<property name="url" value="jdbc:mybatis://localhost:3306/ibatis_demo"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</dataSource>
(3)添加了driver的值,再次運行,又報錯【### Error querying database. Cause: java.sql.SQLException: No suitable driver found for jdbc:mybatis://localhost:3306/ibatis_demo】,又回頭查看了下配置文件,發現 jdbc:mybatis 寫錯,應該爲 jdbc:mysql。mybatis
再運行,ok。app