当前位置:  开发笔记 > 编程语言 > 正文

com.microsoft.sqlserver.jdbc.SQLServerException:不支持"variant"数据类型

如何解决《com.microsoft.sqlserver.jdbc.SQLServerException:不支持"variant"数据类型》经验,为你挑选了1个好方法。

我想创建显示MSSQL服务器版本的简单Java代码:

public void testMSSQLVersion() throws Exception
    {
        System.out.println("\nTesting SQL query for MSSQL version\n");

        try
        {
            // Load the SQLServerDriver class, build the
            // connection string, and get a connection
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String connectionUrl = "jdbc:sqlserver://localhost:1433;"
                + "database=master;"
                + "user=admin;"
                + "password=dss!Q;";
            Connection con = DriverManager.getConnection(connectionUrl);
            System.out.println("Connected.");

            // Create and execute an SQL statement that returns some data.
            String SQL = "SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')";
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(SQL);

            // Iterate through the data in the result set and display it.
            while (rs.next())
            {
                System.out.println(rs.getString(1));
            }

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

但是,当我运行代码时,我收到此错误:

com.microsoft.sqlserver.jdbc.SQLServerException: The "variant" data type is not supported.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
    at com.microsoft.sqlserver.jdbc.TypeInfo$Builder$16.apply(dtv.java:1996)
    at com.microsoft.sqlserver.jdbc.TypeInfo$Builder.build(dtv.java:2158)

这个问题有什么解决方案吗?



1> Devart..:
SELECT ProductVersion = CAST(SERVERPROPERTY('ProductVersion') AS NVARCHAR(128)),
       ProductLevel = CAST(SERVERPROPERTY('ProductLevel') AS NVARCHAR(128)),
       Edition = CAST(SERVERPROPERTY('Edition') AS NVARCHAR(128))

推荐阅读
oDavid_仔o_880
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有