Troubleshooting

   

Setting Up the Correct JDBC URL

The attempt at creating a database connection using a JDBC driver fails.

Because each JDBC driver vendor has flexibility to use a slightly different JDBC URL, you can never really guess at the format of the URL. As mentioned earlier in this chapter, the URL has the following format:

 jdbc:<subprotocol>:<subname> 

Remember that a colon must separate each section. The protocol for a JDBC URL is always jdbc. The subprotocol and the subname is the part that will vary across vendors . It usually depends also on the driver type that the driver implements as well. The best advice is to read the documentation thoroughly when setting up the database URL. There really is no standard way except to read the documentation.

The other thing that might go wrong is the actual connection to the database. Make sure you are providing the username and password in the format that the driver needs. Remember there are three getConnection() methods that get the username and password from different places. Check the documentation as to which the driver is expecting.

Finding the JDBC Driver Class

When loading a database driver using the Class.forName method, a ClassNotFoundException is thrown.

The cause of this problem is most always that the driver is not in your system CLASSPATH. The best thing to do is to "echo" or "cat" the system CLASSPATH at the command line and see if the driver is in your CLASSPATH. The driver can be inside a JAR or ZIP file, so look for that file if it is. Remember, you can open a JAR or ZIP file and look to see if the class is in there. You might need to do this to make sure you are loading the correct JAR or ZIP file. Sometimes a vendor will provide multiple JAR s. One can be a larger development JAR file, whereas another one is built for distribution and contains fewer class files.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net