我正在编写自己的自定义 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