java - 我可以将 Derby EmbeddedDriver 与 Java 教程中指定的 CachedRowSet 示例一起使用吗?
问题描述
在JDBC 教程中有几个可以运行的示例 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。)
臭名昭著的 java.sql.SQLException:找不到合适的驱动程序- 涵盖了 derby 的客户端/服务器实现
SQLException: 没有为 jdbc:derby://localhost:1527 找到合适的驱动程序- 客户端-服务器,未嵌入
JDBC DERBY 找不到合适的驱动程序错误- 不是 RowSet 实例化
找不到适合 jdbc:derby://localhost:1527/prosto 的驱动程序- 客户端/服务器,未嵌入
http://apache-database.10148.n7.nabble.com/No-suitable-driver-found-for-jdbc-derby-td108280.html - 使用Class.forName
;没有行集
JDBC 嵌入式 Derby:找不到合适的驱动程序- 根本原因:连接字符串上的语法错误
解决方案
事实证明,这些教程最近可能没有使用 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
...
推荐阅读
- amazon-web-services - AWS Sagemaker - ClientError:数据下载失败:无法下载
- sql - 如果所有记录都存在于 sql server 的另一个表中,则返回行列表
- java - Spring 2.4.2 - 应用程序属性不会覆盖包含库中的属性
- gmail-api - Gmail API 将访问权限限制为仅一个组
- c - 第一次将页面加载到物理内存中会导致严重的页面错误吗?
- excel - Excel 日期前面有前导空格……
- python - 如何在 Windows 上为 RTX 3070 设置 Tensorflow?
- java - 允许在 Spring WebFlux 中填充 ServerWebExchange.LogPrefix 以进行 UniqueRequestId 日志记录
- java - 为什么我无法找到如果我的字符串在我的 java 代码中只包含重复字符?
- unity3d - 如何在统一 2D 中碰撞触发器和非触发器?