报错提示

报错提示

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <!--    开启驼峰命名转换-->
    <settings>
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
    <!--    设置默认指向的数据库dev-->
    <environments default="dev">
        <!--    配置环境,不同的环境不同的id名字-->
        <environment id="dev">
            <!--        采用JDBC方式对数据库事务进行commit/rollback-->
            <transactionManager type="JDBC"></transactionManager>
            <!--        采用连接池方式管理数据库连接-->
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/imooc_oa?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
                <property name="username" value="root"/>
                <property name="password" value="1644661573"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <mapper resource="mappers/test.xml"/>
    </mappers>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="test">
    <select id="sample" resultType="String">
        select '臭老弟'
    </select>
</mapper>

https://img1.sycdn.imooc.com//climg/634f4ebf09717bf625601600.jpg

https://img1.sycdn.imooc.com//climg/634f4ec609bad36625601600.jpg

报错提示:### Error querying database.  Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jdbc.driver

老师这种情况怎么办啊

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小脸 2022-10-19 10:04:30

同学你好,这里Driver开头的D要大写,修改之后再运行试试

https://img1.sycdn.imooc.com//climg/634f5b1709e264af05520084.jpg

祝学习愉快~


  • 提问者 Star3327752 #1

    改大学会提示已经弃用Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

    https://img1.sycdn.imooc.com//climg/63513f0109949ddc25601600.jpg

    2022-10-20 20:28:56
  • 好帮手慕小脸 回复 提问者 Star3327752 #2

    同学你好,根据报错信息:这里可能是时区问题导致的报错。建议同学在连接数据库时,添加serverTimezone的时区设置

    https://img1.sycdn.imooc.com//climg/6351f6fb097181b511200218.jpg

    比如:jdbc:mysql://localhost:3306/imooc_oa?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai

    祝学习愉快~

    2022-10-21 09:38:06
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师