//———————————————————————- — // fooBar // Do nothing but put two SQLWarnings on our local // warning stack (lastWarning) and a DataTruncation // warning. //———————————————————————- — 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″)); // And create a DataTruncation indicating that a truncation // occurred on column 1, 1000 bytes were requested to // read, and only 999 bytes were read. setWarning(new DataTruncation(1, false, true, 1000, 999); } Listing 10.5 shows the modified code to handle the DataTruncation. Listing 10.5 Processing DataTruncation 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) { // The only way we can tell if this warning is a DataTruncation // is to attempt to cast it. This may fail, indicating that // it is just an SQLWarning. try { DataTruncation trunc = (DataTruncation) chain; System.out.println(”Data Truncation on column: ” + trunc.getIndex()); } catch (Exception ex) { System.out.println(”Message: ” + chain.getMessage()); }
Our stuff is composed of devoted and highly-tainted professionals, creating a mix of powerful and high-quality web hosting perl services, check web hosting perl.