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