Question

I've an stored procedure in Informix (11.50.FC8) returning several values.

The following code (which was part of a more complex query) fails:

String sql = "SELECT * FROM TABLE(FUNCTION my_stored_procedure(?))";
Connection con = dataSource.getConnection();
PreparedStatement ps = con.prepareStatement(sql);

The exception trace is:

 Exception in thread "main" java.sql.SQLException: 
 System error - unexpected null pointer encountered.
 at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:379)
 at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:3109)
 at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3419)
 at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2282)
 at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2202)
 at com.informix.jdbc.IfxSqli.executePrepare(IfxSqli.java:1093)
 at com.informix.jdbc.IfxResultSet.executePrepare(IfxResultSet.java:189)
 at com.informix.jdbc.IfxPreparedStatement.setupExecutePrepare(IfxPreparedStatement.java:193)
 at com.informix.jdbc.IfxPreparedStatement.<init>(IfxPreparedStatement.java:171)
 at com.informix.jdbc.IfxSqliConnect.prepareStatement(IfxSqliConnect.java:1964)
 at test.Main.main(Main.java:27)

The query does not fail if I write it as

SELECT * FROM TABLE(FUNCTION my_stored_procedure(1))

Question: How can I specify the parameter?

I tried preparing a CallableStatement as {call my_stored_procedure(?)} (and it worked) but I need to construct a query that merges several results from the same procedure, with different parameters, as in:

SELECT * FROM TABLE(FUNCTION my_stored_procedure(1))
UNION SELECT * FROM TABLE(FUNCTION my_stored_procedure(2))

No correct solution

OTHER TIPS

You have shown us piece of code, but there is no PreparedStatement parameter set.

This code should look like:

PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, 1);
ResultSet rs = ps.executeQuery();
...

PS In case of problems try to use newest JDBC driver and show us its version. For example I use drivers from JDBC.4.10.JC2DE.tar

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top