| Author |
Calling a DB2 UDF within Java
|
Brad Messerle
Greenhorn
Joined: Jun 30, 2006
Posts: 4
|
|
I can execute the following sql inside the db2 command center and works fine. values GetInvRespCntClmId(1); Java Code public String xyz(Connection con,int anInteger){ int responces = 0; PreparedStatement pstmt = null; try { pstmt = con.prepareStatement("values GetInvRespCntClmId(?)"); pstmt.setInt(1, anInteger); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { responces = rs.getInt(1); } rs.close(); pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } finally { try { pstmt.close(); } catch (SQLException e1) { e1.printStackTrace(); } } return new Integer(responces).toString(); } I get a DB2 --- DB2 SQL error: SQLCODE: -418, SQLSTATE: 42610, SQLERRMC: null Any suggestions? Thank You!
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26141
|
|
Brad, Values() is a function in db2, not a SQL statement. So it wouldn't work from JDBC. You could create a select that goes against a system table and just return one row with that function call. This is the technique Oracle uses for getting the system date.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Brad Messerle
Greenhorn
Joined: Jun 30, 2006
Posts: 4
|
|
What I did was create a view that I could create a query against. Is this what you suggested? Can elebrate on creating a select statement against a system table? Thanks!
|
 |
Brad Messerle
Greenhorn
Joined: Jun 30, 2006
Posts: 4
|
|
Here is the sql statement i came up with but i cant get it to work from jdbc select SumRecommendedLow(?) from xyz fetch first 1 row only Can you please provide a sample sql statement calling a udf? Thanks!
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26141
|
|
This is the idea behind what I was thinking since xyz could be any table. What happens when you try to call it from JDBC? Does it work if you hard code the parameter instead of using the "?" ?
|
 |
 |
|
|
subject: Calling a DB2 UDF within Java
|
|
|