Create Tables with CLOB Columns

This section describes how to create tables with CLOB (VARCHAR(MAX)) columns in SQL Server server.

SQL Server support CLOB with the regular VARCHAR data types, but with a special length value called MAX:

In order to test CLOB columns in SQL Server server, I used the SQL Server command line interface to create a test table with one CLOB column:

herong> sqlcmd -S localhost -U Herong -P T0pSecret

1> -- Set AdventureWorks as the current database
2> USE AdventureWorksLT2019;
3> GO

1> -- Create the test table with a CLOB column
2> CREATE TABLE Article (ID INTEGER PRIMARY KEY IDENTITY,
3>   Subject VARCHAR(256) NOT NULL,
4>   Body VARCHAR(MAX));
5> GO

Table of Contents

 About This Book

 JDBC (Java Database Connectivity) Introduction

 JDK (Java SE) Installation

 Microsoft SQL Server Express Edition

 Microsoft JDBC Driver for SQL Server

 Microsoft JDBC Driver - Query Statements and Result Sets

 Microsoft JDBC Driver - DatabaseMetaData Object

 Microsoft JDBC Driver - DDL Statements

 Microsoft JDBC Driver - DML Statements

 SQL Server - PreparedStatement

SQL Server CLOB (Character Large Object) - TEXT

 Overview of CLOB (Character Large Object)

Create Tables with CLOB Columns

 Inserting CLOB Values with SQL INSERT Statements

 Inserting CLOB Values with setString() Method

 Inserting CLOB Values with setCharacterStream() Method

 Closing InputStream Too Early on setCharacterStream()

 Retrieving CLOB Values with getString() Method

 Retrieving CLOB Values with getCharacterStream() Method

 Retrieving CLOB Values with getClob() Method

 Inserting CLOB Values with setClob() Method

 SQL Server BLOB (Binary Large Object) - BLOB

 JDBC-ODBC Bridge Driver - sun.jdbc.odbc.JdbcOdbcDriver

 JDBC-ODBC Bridge Driver - Flat Text Files

 JDBC-ODBC Bridge Driver - MS Access

 JDBC-ODBC Bridge Driver - MS SQL Server

 Archived Tutorials

 References

 Full Version in PDF/EPUB