![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]()
(chat, newsreader, calendar)
|
![]() |
|
Course Notes Table of Contents | Exercises JDBC Short Course Index | Online Training Index
|
SQL Warning/Exception Handling |
Working Applet | Help Solution
|
PrerequisitesSkeleton CodeThis exercise results in an application that will directly deal with many runtime problems you may have while using JDBC. These problems existed in the earlier exercises, but you dealt with them in a more general way, just catching problems with a generic catch (Exception) block. In addition, the application will behave differently based upon the capabilities of the data source/driver. You will look at the database metadata and do an INSERT statement differently based upon the capabilities of the source. When dealing with exceptions in this exercise, try to be as specific as possible in your catch blocks.
Perform the following tasks:
There are two try blocks that try to load the JDBC-ODBC driver. The first will fail, the second will succeed so you can continue with the rest of the exercise. For both, fill in the catch block with the proper exception. Next, the system attempts to create a Connection to the DriverManager using an invalid URL. Catch the appropriate exception here, too. Also, in the catch block, display the error code, message, and state of the exception. The printSQLWarnings method is needed for the rest of the code. It is your job to create it. This method accepts one parameter of a SQLWarning. For each SQLWarning in the chain, print out all the available information about the warning. If the SQLWarning happens to be a DataTruncation warning, display information about that, too. Call printSQLWarnings to print out any warning messages for every time you use a Connection, ResultSet, or Statement. Using the DatabaseMetaData, determine the level of ANSI92 SQL supported by the database and the SQL grammar level supported by the ODBC driver. Create and populate a new table: students2 from information in an existing table, students.
|
Copyright © 1997 MageLang Institute. All Rights Reserved May-97 Copyright © 1996, 1997 Sun Microsystems Inc. All Rights Reserved |