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