KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > sql > DataTruncation


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
8 package java.sql;
9
10 /**
11  * An exception that reports a
12  * DataTruncation warning (on reads) or throws a DataTruncation exception
13  * (on writes) when JDBC unexpectedly truncates a data value.
14  *
15  * <P>The SQLstate for a <code>DataTruncation</code> is <code>01004</code>.
16  */

17
18 public class DataTruncation extends SQLWarning JavaDoc {
19
20     /**
21      * Creates a <code>DataTruncation</code> object
22      * with the SQLState initialized
23      * to 01004, the reason set to "Data truncation", the
24      * vendorCode set to the SQLException default, and
25      * the other fields set to the given values.
26      *
27      * @param index The index of the parameter or column value
28      * @param parameter true if a parameter value was truncated
29      * @param read true if a read was truncated
30      * @param dataSize the original size of the data
31      * @param transferSize the size after truncation
32      */

33     public DataTruncation(int index, boolean parameter,
34               boolean read, int dataSize,
35               int transferSize) {
36     super("Data truncation", "01004");
37     this.index = index;
38     this.parameter = parameter;
39     this.read = read;
40     this.dataSize = dataSize;
41     this.transferSize = transferSize;
42     DriverManager.println(" DataTruncation: index(" + index +
43                   ") parameter(" + parameter +
44                   ") read(" + read +
45                   ") data size(" + dataSize +
46                   ") transfer size(" + transferSize + ")");
47     }
48
49     /**
50      * Retrieves the index of the column or parameter that was truncated.
51      *
52      * <P>This may be -1 if the column or parameter index is unknown, in
53      * which case the <code>parameter</code> and <code>read</code> fields should be ignored.
54      *
55      * @return the index of the truncated paramter or column value
56      */

57     public int getIndex() {
58     return index;
59     }
60
61     /**
62      * Indicates whether the value truncated was a parameter value or
63      * a column value.
64      *
65      * @return <code>true</code> if the value truncated was a parameter;
66      * <code>false</code> if it was a column value
67      */

68     public boolean getParameter() {
69     return parameter;
70     }
71
72     /**
73      * Indicates whether or not the value was truncated on a read.
74      *
75      * @return <code>true</code> if the value was truncated when read from
76      * the database; <code>false</code> if the data was truncated on a write
77      */

78     public boolean getRead() {
79     return read;
80     }
81
82     /**
83      * Gets the number of bytes of data that should have been transferred.
84      * This number may be approximate if data conversions were being
85      * performed. The value may be <code>-1</code> if the size is unknown.
86      *
87      * @return the number of bytes of data that should have been transferred
88      */

89     public int getDataSize() {
90     return dataSize;
91     }
92
93     /**
94      * Gets the number of bytes of data actually transferred.
95      * The value may be <code>-1</code> if the size is unknown.
96      *
97      * @return the number of bytes of data actually transferred
98      */

99     public int getTransferSize() {
100     return transferSize;
101     }
102
103     /**
104     * @serial
105     */

106     private int index;
107
108     /**
109     * @serial
110     */

111     private boolean parameter;
112
113     /**
114     * @serial
115     */

116     private boolean read;
117
118     /**
119     * @serial
120     */

121     private int dataSize;
122
123     /**
124     * @serial
125     */

126     private int transferSize;
127
128 }
129
Popular Tags