SQL Server Error: Com.microsoft.sqlserver.jdbc.SQLServerException:The "Variant" data type is not supported.

Source: Internet
Author: User

Query a table structure in SQL SERVER with the following SQL statement:

SELECT    tb.name AS tableName,    col.name AS columnName,    col.max_length AS length,    col.is_nullable AS isNullable,    t.name AS type,    (    SELECT        TOP 1 ind.is_primary_key    FROM        sys.index_columns ic        LEFT JOIN sys.indexes ind ON ic.object_id = ind.object_id AND ic.index_id= ind.index_id AND ind.name LIKE ‘PK_%‘    WHERE        ic.object_id = tb.object_id AND ic.column_id= col.column_id    ) AS isPrimaryKey,    com.value AS commentFROM    sys.TABLES tb    INNER JOIN sys.columns col ON col.object_id = tb.object_id    LEFT JOIN sys.types t ON t.user_type_id = col.user_type_id    LEFT JOIN sys.extended_properties com ON com.major_id = col.object_id    AND com.minor_id = col.column_idWHERE    tb.name = ‘表名‘

The SQL can execute normally, but when the SQL is put into the jdbctemplate to perform the Times error:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The "variant" data type is not supported.

The reason is that there is a type property behind the SQL statement select sql_variant and it is not supported in JDBC. Using the sp_columns command to finally isolate the sys.extended_properties value properties of the table TYPE_NAME is sql_variant type, SQL is as follows:

sp_columns extended_properties

The workaround is CONVERT to use the function to turn the property into a varchar type.

The usage of the CONVERT function is referenced in the use of the CONVERT () function in SQL Server.

The modified SQL statement is:

SELECT    tb.name AS tableName,    col.name AS columnName,    col.max_length AS length,    col.is_nullable AS isNullable,    t.name AS type,    (    SELECT        TOP 1 ind.is_primary_key    FROM        sys.index_columns ic        LEFT JOIN sys.indexes ind ON ic.object_id = ind.object_id AND ic.index_id= ind.index_id AND ind.name LIKE ‘PK_%‘    WHERE        ic.object_id = tb.object_id AND ic.column_id= col.column_id    ) AS isPrimaryKey,    CONVERT(varchar(200), com.value) AS commentFROM    sys.TABLES tb    INNER JOIN sys.columns col ON col.object_id = tb.object_id    LEFT JOIN sys.types t ON t.user_type_id = col.user_type_id    LEFT JOIN sys.extended_properties com ON com.major_id = col.object_id    AND com.minor_id = col.column_idWHERE    tb.name = ‘表名‘

Reference:

Com.microsoft.sqlserver.jdbc.SQLServerException:The "Variant" data type is not supported.

SQL Server Error: Com.microsoft.sqlserver.jdbc.SQLServerException:The "Variant" data type is not supported.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.