dagblog.
← Archive

A Bug in the Microsoft SQLServer 2000 Driver for JDBC?


There’s an interesting bug, if it is one, in the Microsoft SQLServer 2000 Driver for JDBC with Java 1.4.2. When it reads a textfield containing an empty string (not null, just a value entered with something like insert into table values ('')), it reports Underlying input stream returned zero bytes. The problem seems to occur only in localized versions of SQLServer 2000. I found two workarounds on the web:

  • Replace the text data type with ntext. I haven’t tested this.
  • Use Java 1.4.0 instead of Java 1.4.2?! I tested this with JRE 1.4.0-b92.

Note: The Sun bug database describes a problem in 1.4.0. More precisely, it’s a problem from 1.2.2 that was fixed in 1.3.x and then returned. When an InputStream is wrapped in an InputStreamReader, for example, a call to isr.read(...) produces Underlying input stream returned zero bytes if is.read(...) on the wrapped stream returns 0.

//pokud is vrátí pomocí read 0, read z isr vyhodí exception

public void wrapStream(InputStream is) throws IOException {

 is.read(new byte[1], 0, 1); //projde

 InputStreamReader isr = new InputStreamReader(is);

 isr.read(new char[1], 0, 1); //vyhodí Underlying...
}

The question, then, is whether Microsoft’s driver should return 0 for an empty string in a textfield, or whether Java should avoid throwing an exception when the wrapper calls read(...) on a stream that returns 0.
Looking at ClobInputStreamu, which is probably the stream that returns 0, the read(...) method does something like this:

int i1 = implClob.readData(abyte0, i, l, k);

currentPosition += i1;

return i1;

The most likely reason for a zero is that currentPosition is 0. In that case it makes sense for the abstract implClob (BaseImplClob) to return 0.

Medium version

Related articles

Related CZ Podcast episodes