Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
508 views
in Technique[技术] by (71.8m points)

java - The conversion from UNKNOWN to UNKNOWN is unsupported

I get the following exception running a stored procedure:

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

The procedure is defined like this:

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

My parameters in Java are defined like this:

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...