내 자신의 JDBC 드라이버를 작성하고 있습니다. 나는 클라이언트 코드 (예 : mysql 커넥터를 사용할 때 jdbc : mysql과 동등)에서 DriverManager.getConnection
에 전달할 URL 접두어를 어떻게 구성 할 수 있는지 궁금합니다. 나는 계속 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;
}
테스트 코드 : 내 코드는 현재 다음과 같습니다 당신은 그것을 한 줄 텍스트 파일 java.sql.Driver
만들기 Driver.boolean acceptsURL(String url)
/**
* Retrieves whether the driver thinks that it can open a connection
* to the given URL. Typically drivers will return <code>true</code> if they
* understand the subprotocol specified in the URL and <code>false</code> if
* they do not.
*
* @param url the URL of the database
* @return <code>true</code> if this driver understands the given URL;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean acceptsURL(String url) throws SQLException;
중복 된 http://stackoverflow.com/questions/861500/url-to-load-resources-from-the-classpath-in-java 및 http://stackoverflow.com/questions/6278299/java-registering -custom-url-protocol-handlers – Vitaly
Vitaly : 저는 맞춤 URL 처리기가 아닌 JDBC를 매우 특별하게 요구하고 있습니다. 언급 한 링크가 DriverManager에 의해 던져진 예외를 어떻게 해결할 수 있는지는 분명하지 않습니다. – JRR
죄송합니다. – Vitaly