1. /*
  2. * @(#)DataTruncation.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. * An exception that reports a
  13. * DataTruncation warning (on reads) or throws a DataTruncation exception
  14. * (on writes) when JDBC unexpectedly truncates a data value.
  15. *
  16. * <P>The SQLstate for a <code>DataTruncation</code> is <code>01004</code>.
  17. */
  18. public class DataTruncation extends SQLWarning {
  19. /**
  20. * Creates a <code>DataTruncation</code> object
  21. * with the SQLState initialized
  22. * to 01004, the reason set to "Data truncation", the
  23. * vendorCode set to the SQLException default, and
  24. * the other fields set to the given values.
  25. *
  26. * @param index The index of the parameter or column value
  27. * @param parameter true if a parameter value was truncated
  28. * @param read true if a read was truncated
  29. * @param dataSize the original size of the data
  30. * @param transferSize the size after truncation
  31. */
  32. public DataTruncation(int index, boolean parameter,
  33. boolean read, int dataSize,
  34. int transferSize) {
  35. super("Data truncation", "01004");
  36. this.index = index;
  37. this.parameter = parameter;
  38. this.read = read;
  39. this.dataSize = dataSize;
  40. this.transferSize = transferSize;
  41. DriverManager.println(" DataTruncation: index(" + index +
  42. ") parameter(" + parameter +
  43. ") read(" + read +
  44. ") data size(" + dataSize +
  45. ") transfer size(" + transferSize + ")");
  46. }
  47. /**
  48. * Retrieves the index of the column or parameter that was truncated.
  49. *
  50. * <P>This may be -1 if the column or parameter index is unknown, in
  51. * which case the <code>parameter</code> and <code>read</code> fields should be ignored.
  52. *
  53. * @return the index of the truncated paramter or column value
  54. */
  55. public int getIndex() {
  56. return index;
  57. }
  58. /**
  59. * Indicates whether the value truncated was a parameter value or
  60. * a column value.
  61. *
  62. * @return <code>true</code> if the value truncated was a parameter;
  63. * <code>false</code> if it was a column value
  64. */
  65. public boolean getParameter() {
  66. return parameter;
  67. }
  68. /**
  69. * Indicates whether or not the value was truncated on a read.
  70. *
  71. * @return <code>true</code> if the value was truncated when read from
  72. * the database; <code>false</code> if the data was truncated on a write
  73. */
  74. public boolean getRead() {
  75. return read;
  76. }
  77. /**
  78. * Gets the number of bytes of data that should have been transferred.
  79. * This number may be approximate if data conversions were being
  80. * performed. The value may be <code>-1</code> if the size is unknown.
  81. *
  82. * @return the number of bytes of data that should have been transferred
  83. */
  84. public int getDataSize() {
  85. return dataSize;
  86. }
  87. /**
  88. * Gets the number of bytes of data actually transferred.
  89. * The value may be <code>-1</code> if the size is unknown.
  90. *
  91. * @return the number of bytes of data actually transferred
  92. */
  93. public int getTransferSize() {
  94. return transferSize;
  95. }
  96. /**
  97. * @serial
  98. */
  99. private int index;
  100. /**
  101. * @serial
  102. */
  103. private boolean parameter;
  104. /**
  105. * @serial
  106. */
  107. private boolean read;
  108. /**
  109. * @serial
  110. */
  111. private int dataSize;
  112. /**
  113. * @serial
  114. */
  115. private int transferSize;
  116. }