Shreyansh Patni
Shreyansh Patni

Reputation: 411

Call Informix ver(12) Procedure in Java

Procedure is being called whenever there is no OUT parameters but whenever the OUT parameters are given the following errors occurs:

java.sql.SQLException: Routine (test) can not be resolved.

Below is my code:

Class.forName("com.informix.jdbc.IfxDriver");
            java.sql.Connection connection =DriverManager.getConnection("jdbc:informix-sqli://server_details");
            CallableStatement stmt = null; 
  String sql = "{call test (?, ?)}";
              stmt =  connection.prepareCall(sql);
                 stmt.registerOutParameter(1,   java.sql.Types.VARCHAR);
                 stmt.registerOutParameter(2,   java.sql.Types.VARCHAR);

                 stmt.execute(); 

Upvotes: 1

Views: 491

Answers (1)

Michał Niklas
Michał Niklas

Reputation: 54322

My simple example of Informix procedure with two OUT parameters called by JDBC CallableStatement works:

db = DriverManager.getConnection(db_url, usr, passwd)
c = db.createStatement()
try:
    c.execute('DROP PROCEDURE test_out_params;')
except:
    pass
c.execute("""CREATE PROCEDURE test_out_params(OUT arg1 VARCHAR(200), OUT arg2 VARCHAR(200))
        LET arg1 = 'arg1';
        LET arg2 = 'arg2';
    END PROCEDURE;""")

stmt = db.prepareCall("{call test_out_params (?, ?)}")
stmt.registerOutParameter(1, Types.VARCHAR)
stmt.registerOutParameter(2, Types.VARCHAR)
stmt.executeQuery()
a1 = stmt.getString(1)
a2 = stmt.getString(2)
print('call result: %s %s\n' % (a1, a2))

I used Jython in this code, and I got:

call result: arg1 arg2

I think you should add simplified source of your test() procedure and more details about your environment, especially Informix server version, and JDBC driver version.

Upvotes: 1

Related Questions