473,756 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

CallableStateme nt cstmt = DB2Connection.g etConnection(). prepareCall("{?
= CALL HEALTHCAREDB.RI SK_EQUATION_1(? )}");

cstmt.registerO utParameter(1,T ypes.DOUBLE);
cstmt.setString (2, rs.getString("P ATIENT_ID"));
cstmt.execute() ;

Here is the error message:
com.ibm.db2.jcc .a.SqlException : DB2 SQL error: SQLCODE: -440, SQLSTATE:
42884, SQLERRMC: HEALTHCAREDB.RI SK_EQUATION_1;P ROCEDURE
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:5 4)
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.jav a: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(t f.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 1866
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.

CallableStateme nt cstmt = DB2Connection.g etConnection(). prepareCall("{?
= CALL HEALTHCAREDB.RI SK_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(parame ter)

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
6898
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 command back into the java app? Example: 1. Execute the 'ls -l' command on the unix machine 2. Grab the reults back into a variable
2
1956
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 File-array. Then it goes through this array and executes the external programm "naccess". naccess takes a file as input and produces 4 output files. Unfortunatly the result files are not in the directory where the input file is (/home/tj/test), they are in...
1
7857
by: jesmi | last post by:
my code is: U]employee.cfm <html> <head> <title>Employee List</title> </head> <body> <h1>Employee List</h1>
0
1072
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: pg74.215.jdbc3.jar i am using jdbc client interface to pgsql database. Although i am able to connect to database server through java progm loading JDBC driver from my console(bash). BUT i am unable to run the same java progm through a html form using php....
3
1482
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 can......need to get this right as soon as i can......... the input goes through the varialbles url and url2------ location of the file this is the error i get java.lang.NoClassDefFoundError: javax/media/ControllerListener at...
0
9455
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10031
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9708
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.