1. /*
  2. * @(#)SQLWarning.java 1.16 01/11/29
  3. *
  4. * Copyright 2002 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. *
  13. * @see Connection#getWarnings
  14. * @see Statement#getWarnings
  15. * @see ResultSet#getWarnings
  16. */
  17. public class SQLWarning extends SQLException {
  18. /**
  19. * Constructs a fully-specified <code>SQLWarning</code> object
  20. * initialized with the given values.
  21. *
  22. * @param reason a description of the warning
  23. * @param SQLState an XOPEN code identifying the warning
  24. * @param vendorCode a database vendor-specific warning code
  25. */
  26. public SQLWarning(String reason, String SQLstate, int vendorCode) {
  27. super(reason, SQLstate, vendorCode);
  28. DriverManager.println("SQLWarning: reason(" + reason +
  29. ") SQLstate(" + SQLstate +
  30. ") vendor code(" + vendorCode + ")");
  31. }
  32. /**
  33. * Constructs an <code>SQLWarning</code> object
  34. * with the given reason and SQLState;
  35. * the vendorCode defaults to 0.
  36. *
  37. * @param reason a description of the warning
  38. * @param SQLState an XOPEN code identifying the warning
  39. */
  40. public SQLWarning(String reason, String SQLstate) {
  41. super(reason, SQLstate);
  42. DriverManager.println("SQLWarning: reason(" + reason +
  43. ") SQLState(" + SQLstate + ")");
  44. }
  45. /**
  46. * Constructs an <code>SQLWarning</code> object
  47. * with the given value for a reason; SQLState defaults to
  48. * null, and vendorCode defaults to 0.
  49. *
  50. * @param reason a description of the warning
  51. */
  52. public SQLWarning(String reason) {
  53. super(reason);
  54. DriverManager.println("SQLWarning: reason(" + reason + ")");
  55. }
  56. /**
  57. * Constructs a default <code>SQLWarning</code> object.
  58. * The reason defaults to null, SQLState
  59. * defaults to null, and vendorCode defaults to 0.
  60. *
  61. */
  62. public SQLWarning() {
  63. super();
  64. DriverManager.println("SQLWarning: ");
  65. }
  66. /**
  67. * Retrieves the warning chained to this <code>SQLWarning</code> object.
  68. *
  69. * @return the next SQLException in the chain, null if none
  70. */
  71. public SQLWarning getNextWarning() {
  72. try {
  73. return ((SQLWarning)getNextException());
  74. } catch (ClassCastException ex) {
  75. // The chained value isn't a SQLWarning.
  76. // This is a programming error by whoever added it to
  77. // the SQLWarning chain. We throw a Java "Error".
  78. throw new Error("SQLWarning chain holds value that is not a SQLWarning");
  79. }
  80. }
  81. /**
  82. * Adds an <code>SQLWarning</code> object to the end of the chain.
  83. *
  84. * @param w the new end of the <code>SQLException</code> chain
  85. */
  86. public void setNextWarning(SQLWarning w) {
  87. setNextException(w);
  88. }
  89. }