Supporting XML Data

Starting with SQL Server 2005, SQL Server provides an xml data type that lets you store XML documents and fragments in a SQL Server database. The xml data type is a built-in data type in SQL Server, and is in some ways similar to other built-in types, such as int and varchar. Like other built-in types, you can use the xml data type as: a variable type, a parameter type, a function-return type, or a column type when you create a table; or in Transact-SQL CAST and CONVERT functions. In the JDBC driver, the xml data type can be mapped as a String, byte array, stream, CLOB, BLOB, or SQLXML object. String is the default mapping.

Starting with the Microsoft SQL Server JDBC Driver version 2.0, the JDBC driver provides support for the JDBC 4.0 API, which introduces the SQLXML interface. The SQLXML interface defines methods to interact with and manipulate XML data. The SQLXML is a JDBC 4.0 data type and it maps to the SQL Server xml data type. Therefore, in order to use the SQLXML data type in your applications, you must set the classpath to include the sqljdbc4.jar file. If the application tries to use the sqljdbc3.jar when accessing the SQLXML object and its methods, an exception is thrown.

Important

SQL Server always validates the XML data before storing it in the database column. The applications that are running on SQL Server 2005 or SQL Server 2008 can use SQLXML data type, because the JDBC driver version 2.0 maps it to the xml data type automatically. However, using SQLXML data type on SQL Server 2000 will throw an exception. The SQLXML support is available in sqljdbc4.jar, which only works on Java Runtime Environment (JRE) 6.0 or later.

The topics in this section describe the SQLXML interface and how to program against the SQLXML data type by using the JDBC API methods.

In This Section

Topic Description

SQLXML Interface

Describes the SQLXML interface and its methods.

Programming with SQLXML

Describes how to use the Microsoft SQL Server JDBC Driver version 2.0 API methods to store and retrieve an XML data in and from a relational database with the SQLXML Java data type. Also contains information about the types of SQLXML objects and provides a list of important guidelines and limitations when using SQLXML objects.

See Also

Other Resources

Understanding the JDBC Driver Data Types