Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...