//———————————————————————- - // fooBar // Do nothing but put two SQLWarnings on our local // warning stack (lastWarning). //———————————————————————- — protected void fooBar() { // First step should always be to clear the stack. If a warning // is lingering, it will be discarded. It is up to the application to // check and clear the stack. setWarning(null); // Now create our warnings setWarning(new SQLWarning(”Warning 1″)); setWarning(new SQLWarning(”Warning 2″)); } Now we ll call the method that puts two SQLWarnings on our warning stack, then poll for the warning using the JDBC method getWarnings, as shown in Listing 10.3. Listing 10.3 Polling for warnings. // Call fooBar to create a warning chain fooBar(); // Now, poll for the warning chain. We’ll simply dump any warning // messages to standard output. SQLWarning chain = getWarnings(); if (chain != null) { System.out.println(”Warning(s):”); // Display the chain until no more entries exist while (chain != null) { System.out.println(”Message: ” + chain.getMessage()); // Advance to the next warning in the chain. null will be // returned if no more entries exist. chain = chain.getNextWarning(); } } DataTruncation objects work in the same manner as SQLWarnings. A DataTruncation object indicates that a data value that was being read or written was truncated, resulting in a loss of data. The DataTruncation class has attributes that can be set to specify the column or parameter number, whether a truncation occurred on a read or a write, the size of the data that should have been transferred, and the number of bytes that were actually transferred. We can modify our code from Listing 10.2 to include the handling of DataTruncation objects, as shown in Listing 10.4. Listing 10.4 Creating dDataTruncation warnings.
We are comcast web hosting company willing to take you step further, please look comcat web hosting services.