Friday, March 13, 2009

If your SQL gets truncated in the process of execution, How would you

Question :If your SQL gets truncated in the process of execution, How would you
know how much of data is trnasfered
and how much of data is left over? (JDBC)

Answer :This can be known using the class DataTruncation. DataTruncation is an
exception that reports a DataTruncation
warning (on reads) or throws a DataTruncation exception (on writes) when
JDBC unexpectedly truncates (meaning
that less information was read or written than requested) a data value. So
all we should do is write our code
using the getDataSize() and getTransferSize() methods of this class in our
catch block trapping this SQLException.
The getDataSize() returns the number of bytes of data that should have
been transferred while the getTransferSize()
method returns the number of bytes of data actually transferred. The
SQLstate for a DataTruncation is 01004.

No comments: