簡體   English   中英

JdbcRowSet返回SQL異常

[英]JdbcRowSet returns SQL Exception

請幫我使用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

}

我不假裝要介紹有效的解決方案,但是最近我在使用Java SE Development Kit 11.0.1 + MySQL Server 8.0.16 + Connector / J 8.0.16驅動程序時創建JdbcRowSetCachedRowSet對象時遇到了同樣的問題。

在將JDK更新為最新版本12.0.1之后,問題就消失了。

聚苯乙烯

但是要做好准備,在成功創建JdbcRowSet對象之后,嘗試更新它時可能會遇到另一種問題。 有關詳細信息,請參見帶有JdbcRowSet的“ java.sql.SQLException:ResultSet無法更新”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM