No suitable driver found for

No suitable driver found for_第1张图片
在学习Mbatis时候遇到的奇怪的问题,报错提示如图所示,提示找不到数据库驱动
检查db.properties文件,一开始认为没问题

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/mybatis?useSSL=false&useUnicode=true&characterEncoding=UTF-8
username=root
password=123456

检查mybatis-config.xml,未发现问题

<environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="${driver}"/>
                <property name="url" value="${url}"/>
                <property name="username" value="${username}"/>
                <property name="password" value="${password}"/>
            dataSource>
        environment>
    environments>

最后参考尚硅谷老师的视频发现在db.properties文件中的键要加上前缀

db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/mybatis?useSSL=false&useUnicode=true&characterEncoding=UTF-8
db.username=root
db.password=123456

同时mybatis-config.xml的取值也要修改

<environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="${db.driver}"/>
                <property name="url" value="${db.url}"/>
                <property name="username" value="${db.username}"/>
                <property name="password" value="${db.password}"/>
            dataSource>
        environment>
    environments>

问题解决,运行成功!
No suitable driver found for_第2张图片

你可能感兴趣的:(java,mybatis)