1. /*
  2. * @(#)SQLWarning.java 1.24 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.sql;
  8. /**
  9. * <P>An exception that provides information on database access
  10. * warnings. Warnings are silently chained to the object whose method
  11. * caused it to be reported.
  12. * <P>
  13. * Warnings may be retrieved from <code>Connection</code>, <code>Statement</code>,
  14. * and <code>ResultSet</code> objects. Trying to retrieve a warning on a
  15. * connection after it has been closed will cause an exception to be thrown.
  16. * Similarly, trying to retrieve a warning on a statement after it has been
  17. * closed or on a result set after it has been closed will cause
  18. * an exception to be thrown. Note that closing a statement also
  19. * closes a result set that it might have produced.
  20. *
  21. * @see Connection#getWarnings
  22. * @see Statement#getWarnings
  23. * @see ResultSet#getWarnings
  24. */
  25. public class SQLWarning extends SQLException {
  26. /**
  27. * Constructs a fully-specified <code>SQLWarning</code> object
  28. * initialized with the given values.
  29. *
  30. * @param reason a description of the warning
  31. * @param SQLstate an XOPEN code identifying the warning
  32. * @param vendorCode a database vendor-specific warning code
  33. */
  34. public SQLWarning(String reason, String SQLstate, int vendorCode) {
  35. super(reason, SQLstate, vendorCode);
  36. DriverManager.println("SQLWarning: reason(" + reason +
  37. ") SQLstate(" + SQLstate +
  38. ") vendor code(" + vendorCode + ")");
  39. }
  40. /**
  41. * Constructs an <code>SQLWarning</code> object
  42. * with the given reason and SQLState;
  43. * the vendorCode defaults to 0.
  44. *
  45. * @param reason a description of the warning
  46. * @param SQLstate an XOPEN code identifying the warning
  47. */
  48. public SQLWarning(String reason, String SQLstate) {
  49. super(reason, SQLstate);
  50. DriverManager.println("SQLWarning: reason(" + reason +
  51. ") SQLState(" + SQLstate + ")");
  52. }
  53. /**
  54. * Constructs an <code>SQLWarning</code> object
  55. * with the given value for a reason; SQLstate defaults to
  56. * <code>null</code>, and vendorCode defaults to 0.
  57. *
  58. * @param reason a description of the warning
  59. */
  60. public SQLWarning(String reason) {
  61. super(reason);
  62. DriverManager.println("SQLWarning: reason(" + reason + ")");
  63. }
  64. /**
  65. * Constructs a default <code>SQLWarning</code> object.
  66. * The reason defaults to <code>null</code>, SQLState
  67. * defaults to <code>null</code>, and vendorCode defaults to 0.
  68. *
  69. */
  70. public SQLWarning() {
  71. super();
  72. DriverManager.println("SQLWarning: ");
  73. }
  74. /**
  75. * Retrieves the warning chained to this <code>SQLWarning</code> object.
  76. *
  77. * @return the next <code>SQLException</code> in the chain; <code>null</code> if none
  78. * @see #setNextWarning
  79. */
  80. public SQLWarning getNextWarning() {
  81. try {
  82. return ((SQLWarning)getNextException());
  83. } catch (ClassCastException ex) {
  84. // The chained value isn't a SQLWarning.
  85. // This is a programming error by whoever added it to
  86. // the SQLWarning chain. We throw a Java "Error".
  87. throw new Error("SQLWarning chain holds value that is not a SQLWarning");
  88. }
  89. }
  90. /**
  91. * Adds an <code>SQLWarning</code> object to the end of the chain.
  92. *
  93. * @param w the new end of the <code>SQLException</code> chain
  94. * @see #getNextWarning
  95. */
  96. public void setNextWarning(SQLWarning w) {
  97. setNextException(w);
  98. }
  99. }