【问题标题】:Can I use the Derby EmbeddedDriver with the CachedRowSet example specified in the Java tutorial?我可以将 Derby EmbeddedDriver 与 Java 教程中指定的 CachedRowSet 示例一起使用吗?
【发布时间】:2021-02-04 22:24:38
【问题描述】:

JDBC Tutorial 中有几个可以运行的示例java 程序。 Ant 目标 runcrs 不运行。当我在嵌入式驱动程序模式下使用 Derby 提供的代码时,crs.execute 出现错误:

try {
  crs.setUsername(settings.userName);
  crs.setPassword(settings.password);
  crs.setUrl(settings.urlString);
  crs.setCommand("select * from MERCH_INVENTORY");

  // Setting the page size to 4, such that we
  // get the data in chunks of 4 rows @ a time.
  crs.setPageSize(100);

  // Now get the first set of data
  crs.execute(); // Throws exception. No suitable driver found.
[java] Found item 6914: Cookbook (12)
[java] Found item 123456: TableCloth (14)
[java] java.sql.SQLException: No suitable driver found for jdbc:derby:testdb
[java]    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
[java]    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
[java]    at java.sql.rowset/com.sun.rowset.internal.CachedRowSetReader.connect(CachedRowSetReader.java:340)
[java]    at java.sql.rowset/com.sun.rowset.internal.CachedRowSetReader.readData(CachedRowSetReader.java:157)
[java]    at java.sql.rowset/com.sun.rowset.CachedRowSetImpl.execute(CachedRowSetImpl.java:809)
[java]    at java.sql.rowset/com.sun.rowset.CachedRowSetImpl.execute(CachedRowSetImpl.java:1435)
[java]    at com.oracle.tutorial.jdbc.CachedRowSetSample.testPaging(CachedRowSetSample.java:98)
[java]    at com.oracle.tutorial.jdbc.CachedRowSetSample.main(CachedRowSetSample.java:254)
[java] SQLState: 08001
[java] Error Code: 0
[java] Message: No suitable driver found for jdbc:derby:testdb

在放弃并寻求解决方案之前,我查看了以下帖子。它们涵盖了非嵌入式(客户端-服务器)实现,它们没有涵盖 CachedRowSet 接口。通常,解决方案是检查 derby.jar 是否在类路径中。 (我检查了——没有运气。此外,驱动程序显然正在加载,因为非 RowSet 功能正在工作,例如,找到项目 123456。)

The infamous java.sql.SQLException: No suitable driver found - 涵盖了 derby 的客户端/服务器实现

SQLException: No suitable driver found for jdbc:derby://localhost:1527 - 客户端-服务器,未嵌入

no suitable driver found error for JDBC DERBY - 不是 RowSet 实例化

No suitable driver found for jdbc:derby://localhost:1527/prosto - 客户端/服务器,未嵌入

http://apache-database.10148.n7.nabble.com/No-suitable-driver-found-for-jdbc-derby-td108280.html - 使用Class.forName;没有行集

JDBC embedded Derby: No suitable driver found - 根本原因:连接字符串语法错误

java.sql.SQLException: No suitable driver found for jdbc:derby: - 根本原因:类路径

【问题讨论】:

  • 您遇到了什么异常?确保包含所有关于你得到的实际异常的信息,这将有助于人们给你最好的建议。这里还有更多内容:cwiki.apache.org/confluence/display/DERBY/UnwindExceptionChain
  • 好点。我几乎害怕因为重复的帖子标签的机会。无论如何,我会添加它。

标签: java jdbc derby


【解决方案1】:

事实证明,这些教程最近可能没有使用 Derby 的 EmbeddedDriver 进行测试。通过将连接对象传递给execute 方法的不同重载,代码无异常执行:

...

public CachedRowSetSample(Connection connArg,
                        JDBCTutorialUtilities settingsArg) {
  super();
  this.con = connArg;

...

try {
  crs.setUsername(settings.userName);
  crs.setPassword(settings.password);
  crs.setUrl(settings.urlString);
  crs.setCommand("select * from MERCH_INVENTORY");

  // Setting the page size to 4, such that we
  // get the data in chunks of 4 rows @ a time.
  crs.setPageSize(100);

  // Now get the first set of data
  crs.execute(con); // Executes without error       // add 'con' (the connection object) as an arg

  ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多