473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Executing sql UDF in java

Hi

I have created a UDF which sits in db2 database.

I want to call that UDF from within a java program and capture the
result.

The UDF takes a string parameter and returns a double value.

This is the code I came up with but it doesnt work and I dont know
whats wrong with it.

CallableStatement cstmt = DB2Connection.getConnection().prepareCall("{?
= CALL HEALTHCAREDB.RISK_EQUATION_1(?)}");

cstmt.registerOutParameter(1,Types.DOUBLE);
cstmt.setString(2, rs.getString("PATIENT_ID"));
cstmt.execute();

Here is the error message:
com.ibm.db2.jcc.a.SqlException: DB2 SQL error: SQLCODE: -440, SQLSTATE:
42884, SQLERRMC: HEALTHCAREDB.RISK_EQUATION_1;PROCEDURE
at com.ibm.db2.jcc.a.rf.e(rf.java:1680)
at com.ibm.db2.jcc.a.rf.a(rf.java:1239)
at com.ibm.db2.jcc.b.jb.h(jb.java:139)
at com.ibm.db2.jcc.b.jb.d(jb.java:71)
at com.ibm.db2.jcc.b.w.d(w.java:54)
at com.ibm.db2.jcc.b.cc.j(cc.java:207)
at com.ibm.db2.jcc.a.rf.o(rf.java:1236)
at com.ibm.db2.jcc.a.sf.ib(sf.java:1805)
at com.ibm.db2.jcc.a.sf.d(sf.java:2264)
at com.ibm.db2.jcc.a.tf.Z(tf.java:159)
at com.ibm.db2.jcc.a.tf.execute(tf.java:142)
at Test.main(Test.java:24)

Could you please tell me whats wrong with teh java code?

Thanks
Mahesh

Dec 5 '06 #1
2 1840
Mahesh S wrote:
Hi

I have created a UDF which sits in db2 database.

I want to call that UDF from within a java program and capture the
result.

The UDF takes a string parameter and returns a double value.

This is the code I came up with but it doesnt work and I dont know
whats wrong with it.

CallableStatement cstmt = DB2Connection.getConnection().prepareCall("{?
= CALL HEALTHCAREDB.RISK_EQUATION_1(?)}");
CALL is used to invoke stored procedures. UDFs are to be used like other
built-in functions and not with the CALL statement. To test a UDF (or to
use it stand-alone), you can employ the VALUES statement:

VALUES your_udf(parameter)

Note that you may have to CAST your parameter if you use parameter markers.
Otherwise, DB2's function resolution does not know which function (depends
on the signature) you really want to use. The cast provides the necessary
type information.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Dec 5 '06 #2
Hi Knut

Thanks. That works.

Cheers

Dec 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Simon Hawkins | last post by:
I seem to remember there's a java function for executing commands on the native system (UNIX in this case) but cannot remember which. Anyone know? Also, is it possible to grab the results of the...
2
by: LordChaos | last post by:
Dear all, I am a newbie in Java, I got the following problem: I am going through a list of directories. The programm looks inside each directory for specific files and writes them in an...
1
by: jesmi | last post by:
my code is: U]employee.cfm <html> <head> <title>Employee List</title> </head> <body> <h1>Employee List</h1>
0
by: mamoon | last post by:
hi all, i am facing a serious problem in running JDBC programm in Apache server environment. Background Information- 1, OS: Enterprise Linux4 running Apache2 2. pgsql8.2 3.JDBC driver:...
3
by: prashfire2000 | last post by:
This is a code i wrote to play a video file usin JMF..... the applet gets started but not initialized..... is the code correct or is there any mistake?????? please help me out as soon as u...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.