【发布时间】:2013-04-08 07:16:17
【问题描述】:
我正在编写自己的自定义 JDBC 驱动程序。我想知道如何在客户端代码中配置要传递给 DriverManager.getConnection 的 URL 前缀(即,在使用 mysql 连接器时相当于 jdbc:mysql )?我似乎不断收到java.sql.SQLException: No suitable driver found。我的代码目前如下所示:
static
{
try
{
CustomDriver driverInst = new CustomDriver();
DriverManager.registerDriver(driverInst);
}
catch (Exception e) { e.printStackTrace(); }
}
public CustomDriver () throws SQLException
{
super();
}
@Override
public Connection connect (String url, Properties info) throws SQLException
{
// this is never called
return null;
}
测试代码:
Class.forName("CustomDriver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection("customDriver://localhost/testdb");
// throws SQLException
【问题讨论】:
-
Vitaly:我特别要求 JDBC,而不是自定义 URL 处理程序。我不清楚您提到的链接如何解决 DriverManager 引发的异常。
-
顺便说一句,它现在工作了吗?
-
@JRR 您好,您成功实现了自己的 JDBC 驱动程序吗?你能分享你的代码吗?我也在尝试实现,但不幸被困在其中 - 或者如果它在你的 github 上 - 请分享 repo 链接。我会很感激的。提前非常感谢。
-
@JRR 你能告诉我如何编写自定义 jdbc 驱动程序吗?如果某处有很好的参考,请帮助我提供链接