【问题标题】:JdbcRowSet returns SQL ExceptionJdbcRowSet 返回 SQL 异常
【发布时间】:2019-05-21 17:05:29
【问题描述】:

请帮助我处理 RowSetProvider,它会引发 SQL 异常

(没有找到适合 jdbc:mysql://localhost:3306 的驱动)

Drivermanager.getConnection() 工作正常。

public static void main(String[] args) throws SQLException {

    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/zoo?serverTimezone=UTC", "hbstudent",
            "hbstudent");
    System.out.println(con.getCatalog()); // <-- works OK

    // ****************************************************

    JdbcRowSet rs = RowSetProvider.newFactory().createJdbcRowSet();

    rs.setUrl("jdbc:mysql://localhost:3306/zoo?serverTimezone=UTC");
    rs.setUsername("hbstudent");
    rs.setPassword("hbstudent");
    rs.setCommand("select 1");
    rs.execute(); //<-- Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/zoo?serverTimezone=UTC

}

【问题讨论】:

  • 是你的运行时类路径上的 MySql jdbc 驱动程序吗?
  • 可能驱动不支持JdbcRowSet
  • @Reimeus 添加 Class.forName("com.mysql.cj.jdbc.Driver") 并检查“Java Build Path”后没有任何变化。
  • @JoakimDanielson 如何查找驱动程序是否支持 JdbcRowSet,我使用的是 mysql-connector-java-8.0.15,假设它是最新的 ont

标签: java


【解决方案1】:

我不假装要介绍有效的解决方案,但最近我在使用 Java SE Development Kit 11.0.1 时创建 JdbcRowSetCachedRowSet 对象时遇到了同样的问题+ MySQL 服务器 8.0.16 + 连接器/J 8.0.16 驱动程序。

将JDK更新为最新版本12.0.1后,问题就消失了。

附言

但是要做好准备,在成功创建 JdbcRowSet 对象后,您在尝试更新它时可能会遇到另一种问题。详情请见"java.sql.SQLException: ResultSet is not updatable" with JdbcRowSet

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-31
    • 2010-12-10
    • 1970-01-01
    • 2018-10-09
    • 2020-01-31
    • 2010-10-05
    • 1970-01-01
    • 2022-07-07
    相关资源
    最近更新 更多