Then I am trying to get a Statement from that Connection:
Statement stmt = connect.createStatement();
(I have also tried:
PreparedStatement pstmt = conenct.prepareStatement(sqlString);
When I make either the createStatement or prepareStatement call, I throw an SQLException with CLI0601E which states, "Invalid statement handle or statement is closed."
I have tested that the connection is open, by calling connect.isClosed(); which returns false. I have also called connect.toString() which dumps connection properties and looks valid.
Is there a way to get a connection back to the database from within a user defined function?
My latest attempt at this was to extend UDF which resulted in the following error:
[IBM][CLI Driver] SQL0487N User defined function or procedure "" (specific name "") attempted to execute an SQL statement. SQLSTATE=38001
What I'm trying to do is get a unique integer id value to use as an id for records in various tables. I was hoping to execute this as a UDF so that I could get the id on inserting from sql code or get the id ahead of time for use in programs executing outside of the database. I got this to work from a stored proc, but I don't know if there's a way to get a value from a stored proc from sql.
I know that DB2 7.2 has something similar to Oracle's sequence which is exactly what I need, but my company can't justify the expense of upgrading from 6.1.
JDBC Connection from Java scalar User Defined Function (UDF)
I had the same problem and the same error message than you. Have you a solution yet? I've read Application Development Guide from the beggining and I don't know what is the problem. Maybe I'm not connected whe I try to create de statement?