Java Reference
In-Depth Information
registers the newly created instance with the DriverManager . Listing 19-3 shows how simple the
XMLDriver is.
Listing 19-3: XMLDriver class
package JavaDatabaseBible.ch19.JDBCforXML;
import java.sql.*;
import java.util.Properties;
import JavaDatabaseBible.ch19.JDBCImpl.JDBCDriverImpl;
public class XMLDriver extends JDBCDriverImpl{
protected XMLConnection con;
static {
try {
java.sql.DriverManager.registerDriver(new XMLDriver());
}catch(SQLException e) {
System.err.println(e);
}
}
public XMLDriver() {
}
public boolean acceptsURL(String url) throws SQLException {
return url.endsWith(".xml");
}
public Connection connect(String url, Properties info)
throws SQLException {
con = new XMLConnection(url);
return con;
}
}
In addition to loading JDBC drivers, the DriverManager attempts to locate a suitable driver for the
specified URL and returns a connection to the appropriate driver. It does this by polling the registered
drivers' acceptsURL(String url) methods.
The DriverManager is also responsible for getting a java.sql.Connection to the database. It
does this by calling the driver's connect() method, passing the URL for the database. The driver then
creates a Connection object and returns it to the DriverManager .
The XMLConnection class
Search WWH ::




Custom Search