- Build the JAR with
mvn clean compile assembly:single
- Create a new database or use an existing one
- Create a new table or use an existing one, which contains a
NVARCHAR(MAX)
column
CREATE TABLE [dbo].[content](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[content] [nvarchar](max) NOT NULL,
CONSTRAINT [PK_content] PRIMARY KEY CLUSTERED ([id] ASC)
);
INSERT INTO [dbo].[content](content) VALUES('hello world');
- Run the test with
java -jar target/mssql-jdbc-clob-exception-1.0-SNAPSHOT-jar-with-dependencies.jar
--help
shows the help- To connect to localhost on port 1933 with user
hello
, passwordworld
and databaseexample
containing the tablecontent
use the following arguments:-h localhost:1933 -u hello -p world -d example -q "select top 5 [id], [content] from [content]"
- The test executes the given query, which processes the
[content]
column by usingjava.sql.ResultSet.getClob(int)
- The mssql-jdbc driver version
9.2.1.jre8
throws anIOException
(Stream Closed) which will be wrapped into acom.microsoft.sqlserver.jdbc.SQLServerException
- The exception is then suppressed in the method
com.microsoft.sqlserver.jdbc.SQLServerResultSet.fillLOBs
. - You should be able to see this behavior in the logs containing a line with
SQLServerResultSet:1Filling Lobs before closing: The stream is closed.
:
2021-04-08 10:39:39.028 [main] INFO o.e.ClobExceptionTester - Connecting to localhost:1933
2021-04-08 10:39:39.669 [main] INFO o.e.ClobExceptionTester - Connection to localhost:1933 established
2021-04-08 10:39:39.669 [main] INFO o.e.ClobExceptionTester - Executing query select top 5 [id], [content] from [content]
2021-04-08 10:39:39.720 [main] DEBUG c.m.s.j.SQLServerResultSet - SQLServerResultSet:1 created by (SQLServerStatement:1)
2021-04-08 10:39:39.720 [main] DEBUG c.m.s.j.SQLServerResultSet - SQLServerResultSet:1 currentRow:0 numFetchedRows:0 rowCount:-3
2021-04-08 10:39:39.732 [main] DEBUG c.m.s.j.SQLServerResultSet - SQLServerResultSet:1 Getting Column:1
2021-04-08 10:39:39.732 [main] DEBUG c.m.s.j.SQLServerResultSet - SQLServerResultSet:1 Getting Column:2
2021-04-08 10:39:39.732 [main] INFO o.e.ClobExceptionTester - Row: [1, hello world]
2021-04-08 10:39:39.732 [main] DEBUG c.m.s.j.SQLServerResultSet - SQLServerResultSet:1 currentRow:1 numFetchedRows:1 rowCount:-3
2021-04-08 10:39:39.732 [main] DEBUG c.m.s.j.SQLServerResultSet - SQLServerResultSet:1Filling Lobs before closing: The stream is closed.
2021-04-08 10:39:39.732 [main] INFO o.e.ClobExceptionTester - Connection to localhost:1933 closed
- If you build the project with the mssql-jdbc driver version
6.2.2
, the exception is not thrown. To verify this, rebuild the JAR with version6.2.2
(pom.xml) and execute the test again.