473,394 Members | 1,869 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,394 software developers and data experts.

Catching values returned by a java program by a DB2 function/stored procedure

Hi,
I am using DB2 v8.2 & jdk 1.4.
1. I have a java program which returns an array which contains 1 to 5
numbers.
The code:
public class ArrayTest
{
public static final int ARRAY_SIZE = 5;
public static int[] array()
{
int array[] = new int[ARRAY_SIZE];
for(int i = 0; i < ARRAY_SIZE ; i++)
{
array[i] = i+1;
}
return array;
}
public static void main(String params[])
{
int a[] = array();
for(int i = 0; i < a.length ; i++)
{
System.out.println(a[i]);
}
}
}
2. Now, I need to catch that values returned by java using a function /
stored procedure in DB2
3. Using the values caught, I need to return a result set like :
select firstname,salary from employee where empno='x' where 'x' is
the value returned by the
java program & caught by DB2 function/stored procedure
So, the logic:
for (i=1;i<x;i++)
{
select firstname,salary from employee where empno='x'
}
should be implemented in the function/stored procedure.
4. This result set should be displayed on the standard output

Please help me out, as this is very urgent for me.

Thanks in advance...........

satish

Dec 4 '06 #1
1 2285
satish mullapudi wrote:
Hi,
I am using DB2 v8.2 & jdk 1.4.
1. I have a java program which returns an array which contains 1 to 5
numbers.
The code:
public class ArrayTest
{
public static final int ARRAY_SIZE = 5;
public static int[] array()
{
int array[] = new int[ARRAY_SIZE];
for(int i = 0; i < ARRAY_SIZE ; i++)
{
array[i] = i+1;
}
return array;
}
public static void main(String params[])
{
int a[] = array();
for(int i = 0; i < a.length ; i++)
{
System.out.println(a[i]);
}
}
}
2. Now, I need to catch that values returned by java using a function /
stored procedure in DB2
3. Using the values caught, I need to return a result set like :
select firstname,salary from employee where empno='x' where 'x' is
the value returned by the
java program & caught by DB2 function/stored procedure
So, the logic:
for (i=1;i<x;i++)
{
select firstname,salary from employee where empno='x'
}
should be implemented in the function/stored procedure.
What exactly have you done so far? (show us the code)

You could simply create the array, then construct a SQL statement like this:

SELECT firstname, salary
FROM employee
WHERE empno IN ( 1, 2, 3, 10 )

where the elements in the IN-clause stem from your array. Finally, execute
the query and open a cursor. The cursor is then returned by the procedure
and could be processed by an application that invoked the procedure.

Another alternative are table functions. You write a table function that
returns your array as table (we are talking SQL here, so you only have
tables!) Then you can join the EMPLOYEE table with the results of your
table function:

SELECT e.firstname, e.salary
FROM TABLE ( your-function() ) AS t(id) JOIN
employee AS e ON ( t.id = e.empno )

Have a look at the DB2 samples to see how table functions and stored
procedures can be implemented.
4. This result set should be displayed on the standard output
I tried to explain the other day that there is no standard output with SQL.
Maybe you want to return the rows as a regular result set? Such a result
set can be processed by an application or you could use the DB2 command
line as application (which has its own standard output).

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

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

Similar topics

4
by: randy.p.ho | last post by:
Using JDBC, is there a way to call a stored procedure with multiple return values? Thanks.
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
5
by: Raquel | last post by:
This is a very simple DB2 SQLJ stored procedure. The problem is that it seems to run fine but returns NOTHING. I mean..as if nothing has happened..not resultset is returned. I am passing value...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
0
by: Juan Carlos Huitzache | last post by:
Hi, I am trying to build a very simple Java stored procedure on DB2 V8.2 for AIX. I use the WSAD 5.1 or the DB2 Development Center with the same result: C:\Program Files\SQLLIB\java\jdk\bin\jar...
2
by: cesark | last post by:
I have calling a stored procedure that returns two values, and I want to catch these values and to store them into a variable. Here is a piece of my SP inside SQL Server that shows the returned...
2
by: Michael | last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP, I am unable to find out why the "Build for Debug" option within Stored Procedure Builder is not enabled on Java stored...
4
by: scparker | last post by:
Hello, We have a stored procedure that does a basic insert of values. I am then able to retrieve the ID number created for this new record. We are currently using ASP.NET 2.0 and use N-Tier...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.