我正在编写自己的自定义JDBC驱动程序。我想知道如何将客户端代码中的URL前缀配置为DriverManager.getConnection(即使用mysql连接器时等同于jdbc:mysql)?我似乎不断得到java.sql.SQLException: No suitable driver found。我的代码当前如下所示:自定义JDBC驱动程序
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
2013-04-16
JRR
+1
http://stackoverflow.com/questions/861500/url-to-load-resources-from-the-classpath-in-java和http://stackoverflow.com/questions/6278299/java-registering - 自定义url的协议处理程序 –
+0
Vitaly:我非常专门问JDBC,而不是一个自定义的URL处理程序。我不清楚你提到的链接如何解决DriverManager抛出的异常。 –
+0
对不起,回答。 –