• 解决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

    在这里插入图片描述

  • 相关阅读:
    Docker部署并启动RabbitMQ
    Spring Boot + BPMN流程管理引擎实践
    分析SSH登录日志
    CSS图文悬停翻转效果完整源码附注释
    python技术面试题合集(二)
    codeforces:C. Zero-Sum Prefixes【前缀和 + 倒序贪心】
    redis运维(十二)
    【Lintcode】198. Permutation Index II
    内网 Ubuntu 20.04 搭建 docusaurus 项目(或前端项目)的环境(mobaxterm、tigervnc、nfs、node)
    纯函数 和 函数柯里化 ( 函数式编程 )05
  • 原文地址:https://blog.csdn.net/xiao_yu503/article/details/126412743