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
412 views
in Technique[技术] by (71.8m points)

jdbc - calling oracle PL/SQL function in java - Invalid column type error

I want to call a plsql function from java class but that function (isValidPeriod) return a boolean datat type and JDBC doesn't support it

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

There is a simple workaround for that restriction, which does not require a wrapper function, simply wrap the boolean function itself in a CASE statement and use an Integer for binding:

stmt = conn.prepareCall(
          "BEGIN"
        + " ? := CASE WHEN (myBooleanFuncInOracle()) "
        + "       THEN 1 "
        + "       ELSE 0"
        + "      END;"
        + "END;");

stmt.registerOutParameter(1, Types.INTEGER);

// exec
stmt.execute();

// get boolean from Integer
boolean myBool = (stmt.getInt(1) == 1);

Very useful if you can't or don't want to change your function or even can't create a wrapper function, i.e. in legacy DBs.


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

...