// Look for the colon that separates the subname // from the subprotocol (or the fact that there // is no subprotocol at all). if (url.startsWith(”:”)) { subname = url.substring(subProtocol.length()); } else if (url.length() == 0) { subname = “”; } } } } return subname; } Driver Properties Connecting to a JDBC driver with only a URL specification is great, but the vast majority of the time, a driver will require additional information in order to properly connect to a database. The JDBC specification has addressed this issue with the getPropertyInfo method. Once a Driver has been instantiated, an application can use this method to find out what required and optional properties can be used to connect to the database. You may be tempted to require the application to embed properties within the URL subname, but by returning them from the getPropertyInfo method, you can identify the properties at runtime, giving a much more robust solution. Listing 10.15 shows an application that loads the SimpleText driver and gets the property information. Listing 10.15 Using the getPropertyInfo method to identify properties at runtime. import java.sql.*; class PropertyTest { public static void main(String args[]) { try { // Quick way to create a driver object java.sql.Driver d = new jdbc.SimpleText.SimpleTextDriver(); String url = “jdbc:SimpleText”; // Make sure we have the proper URL if (!d.acceptsURL(url)) { throw new SQLException(”Unknown URL: ” + url); } // Setup a Properties object. This should contain an entry // for all known properties to this point. Properties that // have already been specified in the Properties object will // not be returned by getPropertyInfo. java.util.Properties props = new java.util.Properties();
Need a managed web hosting provider to help maintain your website? Our web hosting service is the preferred choice of thousands of demanding customers.