![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e242. Determining If a SQL Warning OccurredSome database operations can cause a warning which is not handled by an exception. These warning must be explicitly checked for. An example of a warning is a data truncation error during a read operation (see theDataTruncation class).
There are three places to check for a warning --- on a
try { // Get warnings on Connection object SQLWarning warning = connection.getWarnings(); while (warning != null) { // Process connection warning // For information on these values, see e241 Handling a SQL Exception String message = warning.getMessage(); String sqlState = warning.getSQLState(); int errorCode = warning.getErrorCode(); warning = warning.getNextWarning(); } // Create a statement Statement stmt = connection.createStatement(); // Use the statement... // Get warnings on Statement object warning = stmt.getWarnings(); if (warning != null) { // Process statement warnings... } // Get a result set ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table"); while (resultSet.next()) { // Use result set // Get warnings on the current row of the ResultSet object warning = resultSet.getWarnings(); if (warning != null) { // Process result set warnings... } } } catch (SQLException e) { }
e236. Connecting to a MySQL Database e237. Connecting to a SQLServer Database e238. Listing All Available Parameters for Creating a JDBC Connection e239. Determining If a Database Supports Transactions e240. Committing and Rolling Back Updates to a Database e241. Handling a SQL Exception e243. Getting the Driver of a Connection e244. Setting the Number of Rows to Prefetch When Executing a SQL Query © 2002 Addison-Wesley. |