• 解决Java异常java.sql.SQLException: Unexpected exception encountered during query.


    解决Java异常java.sql.SQLException: Unexpected exception encountered during query.

    问题

    在学习Java的servlet过程中,学习到MySQL连接的部分时,配置都正确的情况下,一直没有得到想要的结果。网页这边一直是200,换浏览器也是200,但是就是空白,一点信息都没有,加上之前忘记MySQL的密码,苦苦思索一周时间了。
    大致内容就是这些数据库的操作
    很普通的数据库增删改查。

    String sql="insert into test(name,account,password) values(?,?,?)";
        //INSERT INTO `school`.`test` (`name`, `account`, `password`) VALUES ('李四', 'uwe', '123123');
        ps=connection.prepareStatement(sql);
        ps.setObject(1,"张三");
        ps.setObject(2,"user001");
        ps.setObject(3,"1234567");
        int result=ps.executeUpdate();
        Writer writer=response.getWriter();
        writer.write("

    成功修改"+result+"条记录

    "); writer.flush(); writer.close();
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    一开始在找[警告],把警告改差不多了,发现最重要的是异常。以下是几条警告:

    1. Client does not support authentication protocol requested by server;consider upgrading MySQL client
    2. At least one JAR was scanned for TLDs yet contained no TLDs.
    3. org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
      接着终于明白过来其实异常才是最重要,搜到了异常的解决方式。这个是异常提示:java.sql.SQLException: Unexpected exception encountered during query.

    解决方案

    在IntelliJ IDEA中,创建库lib,用来放入驱动程序,我之前用的是mysql-connector-java-5.1.18-bin.jar的,换这个mysql-connector-java-5.0.8-bin.jar即可。
    下载地址参考这篇文章
    https://goodluckpeng.blog.csdn.net/article/details/115376310?spm=1001.2014.3001.5502
    mysql-connector-java-5.0.8-bin.jar下载地址放这里:
    https://mvnrepository.com/artifact/mysql/mysql-connector-java
    连接之后的代码如下所示,至于还有一个警告,目前还未解决。

    Connected to server
    [2022-08-18 07:36:31,273] Artifact webTest:war exploded: Artifact is being deployed, please wait…
    18-Aug-2022 19:36:32.908 信息 [RMI TCP Connection(5)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
    [2022-08-18 07:36:33,140] Artifact webTest:war exploded: Artifact is deployed successfully
    [2022-08-18 07:36:33,141] Artifact webTest:war exploded: Deploy took 1,867 milliseconds
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在这里插入图片描述

  • 相关阅读:
    新增文章出现bug怎么定位是前端问题还是后端问题
    深度学习笔记_1、定义神经网络
    iBooker 技术评论 20230909
    老男孩教育|0基础转行学Linux,完美逆袭,收获满意Offer!
    vue3+elementPlus:el-select选择器里添加按钮button
    关系数据库事务中的对象锁定
    舵机驱动——STM32F407ZGT6探索者——HAL库
    C++查漏补缺与新标准(C++20,C++17,C++11)01 C++快速回顾(一)
    Vue 高级特性总结
    open-webui与ollama的部署最后完整之命令
  • 原文地址:https://blog.csdn.net/xiao_yu503/article/details/126412743