Saturday, December 22nd, 2007
// // Returns true if this driver can connect to the given URL. The class loader will create a new instance of the SimpleText JDBC driver. The application then asks the DriverManager to create a connection using the given URL. If the SimpleText driver does not register itself, the DriverManager will not attempt to load it, which will result in a nasty No capable driver error. The best place to register a driver is in the Driver constructor: public SimpleTextDriver() throws SQLException { // Attempt to register this driver with the JDBC DriverManager. // If it fails, an exception will be thrown. DriverManager.registerDriver(this); } URL Processing As I mentioned a moment ago, the acceptsURL method informs the DriverManager whether a given URL is supported by the driver. The general format for a JDBC URL is jdbc:subprotocol:subname where subprotocol is the particular database connectivity mechanism supported (note that this mechanism may be supported by multiple drivers) and the subname is defined by the JDBC driver. For example, the format for the JDBC-ODBC Bridge URL is: jdbc:odbc:data source name Thus, if an application requests a JDBC driver to service the URL of jdbc:odbc:foobar the only driver that will respond that the URL is supported is the JDBC-ODBC Bridge; all others will ignore the request. Listing 10.14 shows the acceptsURL method for the SimpleText driver. The SimpleText driver will accept the following URL syntax: jdbc:SimpleText Note that no subname is required; if a subname is provided, it will be ignored. Listing 10.14 The acceptsURL method. //———————————————————————- — // acceptsURL - JDBC API // // Returns true if the driver thinks that it can open a connection // to the given URL. Typically, drivers will return true if they // understand the subprotocol specified in the URL, and false if // they don’t. // url The URL of the database. //
Pay us little and get a lot! We will give you the cheapest web hosting available, trust us and check cheapest web hosting services.