从UNKNOWN到UNKNOWN的转换不受支持 [英] The conversion from UNKNOWN to UNKNOWN is unsupported

查看:3249
本文介绍了从UNKNOWN到UNKNOWN的转换不受支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行存储过程时出现以下异常:

I get the following exception running a stored procedure:

com.microsoft.sqlserver.jdbc.SQLServerException:不支持从UNKNOWN到UNKNOWN的转换。

com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to UNKNOWN is unsupported.

程序定义如下:

CREATE PROCEDURE spTest (
@p1 varchar(1024) ,
@p2 varchar(1024) ,
@p3 char(1) ,
@p4 varchar(254),
@p5 varchar(254),
@debug bit )

我在Java中的参数定义如下:

My parameters in Java are defined like this:


Object [] params = {1,2,3,d,'2',,,1} ;

Object[] params = {"1,2,3", "d", '2', "", "", 1};

我认为这是由角色造成的。有什么想法吗?

I think it's caused by the character. Any ideas why?

推荐答案

我找到了。发条 - 缪斯让我走上了正轨。设置参数时,char类型不会转换为Object。以下将起作用:

I found it. Clockwork-Muse put me on the path. The char type does not convert to an Object when you set the parameters. The following will work:

     try (PreparedStatement st = con.prepareStatement(query)) {
        int n = 1;
        for (Object o : params) {

            if (o instanceof Character) {
                o = "" + o;
            }

            st.setObject(n, o);
            n++;
        }
        st.executeQuery();
    }

这篇关于从UNKNOWN到UNKNOWN的转换不受支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆