Link, David A
2013-05-02 21:25:11 UTC
We are having issues with getting java to find the stored procedure when the argument is a SET. Below is the stored procedure and the java code. We are running AIX 11.50. FC9XA. Any help for this non-java DBA would be greatly appreciated.
Thanks,
David
-----------------------------------------------------------------------------------------------------------------------------------------
package com.west.wic.test;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import javax.swing.text.html.HTMLDocument.HTMLReader.PreAction;
/**
* @author aacharya
*
* @description
* This class uses the CallableStatement to call a stored procedure using
* SET(ROW()).
*
* This stored procedure resides inside ibm387 drain_system database
*
* CREATE PROCEDURE TESTING_SET(TEST_SET SET(CHAR(10) NOT NULL))
RETURNING CHAR(10);
DEFINE element CHAR(10);
FOREACH SELECT * INTO element FROM TABLE(TEST_SET)
RETURN element WITH RESUME;
END FOREACH;
END PROCEDURE;
*
* To Drop the procedure:
* DROP PROCEDURE TESTING_SET
*
* @example
* EXECUTE PROCEDURE TESTING_SET(SET{'GroupTestHash1', 'GroupTestHash2'})
*
*
*/
public class HashSetTest {
/**
* @param args
*/
public static void main(String[] args) {
CallableStatement statement = null;
String sqlStatement = null;
ResultSet resultset = null;
HashSet<String> groupIdSet = new HashSet<String>();
try {
//Prepare the Set
groupIdSet.add("GroupTestHash1");
groupIdSet.add("GroupTSestHash2");
//Loads the driver class
Class.forName ("com.informix.jdbc.IfxDriver");
Connection connection = DriverManager.getConnection("jdbc:informix-sqli://ibmXXX:YYY/test_system:INFORMIXSERVER=ibmXXX;user=USERID;password=PASSWORD");
// Create the statement object
sqlStatement = "{call TESTING_SET(?)}";
statement = connection.prepareCall(sqlStatement);
statement.setQueryTimeout(10);
// Set the parameters in the stored procedure
statement.setObject(1, groupIdSet);
statement.execute();
resultset = statement.getResultSet();
// resultset = statement.executeQuery();
// Traverse the resultset to get response
while(resultset.next())
{
System.out.println(resultset.getString(1));
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("error message:" +e.getMessage());
System.out.println("error code:" + e.getErrorCode());
}
}
}
Thanks,
David
-----------------------------------------------------------------------------------------------------------------------------------------
package com.west.wic.test;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import javax.swing.text.html.HTMLDocument.HTMLReader.PreAction;
/**
* @author aacharya
*
* @description
* This class uses the CallableStatement to call a stored procedure using
* SET(ROW()).
*
* This stored procedure resides inside ibm387 drain_system database
*
* CREATE PROCEDURE TESTING_SET(TEST_SET SET(CHAR(10) NOT NULL))
RETURNING CHAR(10);
DEFINE element CHAR(10);
FOREACH SELECT * INTO element FROM TABLE(TEST_SET)
RETURN element WITH RESUME;
END FOREACH;
END PROCEDURE;
*
* To Drop the procedure:
* DROP PROCEDURE TESTING_SET
*
* @example
* EXECUTE PROCEDURE TESTING_SET(SET{'GroupTestHash1', 'GroupTestHash2'})
*
*
*/
public class HashSetTest {
/**
* @param args
*/
public static void main(String[] args) {
CallableStatement statement = null;
String sqlStatement = null;
ResultSet resultset = null;
HashSet<String> groupIdSet = new HashSet<String>();
try {
//Prepare the Set
groupIdSet.add("GroupTestHash1");
groupIdSet.add("GroupTSestHash2");
//Loads the driver class
Class.forName ("com.informix.jdbc.IfxDriver");
Connection connection = DriverManager.getConnection("jdbc:informix-sqli://ibmXXX:YYY/test_system:INFORMIXSERVER=ibmXXX;user=USERID;password=PASSWORD");
// Create the statement object
sqlStatement = "{call TESTING_SET(?)}";
statement = connection.prepareCall(sqlStatement);
statement.setQueryTimeout(10);
// Set the parameters in the stored procedure
statement.setObject(1, groupIdSet);
statement.execute();
resultset = statement.getResultSet();
// resultset = statement.executeQuery();
// Traverse the resultset to get response
while(resultset.next())
{
System.out.println(resultset.getString(1));
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("error message:" +e.getMessage());
System.out.println("error code:" + e.getErrorCode());
}
}
}