If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Update ResultSet In Java Stored Procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-19-11, 16:02
pczurak pczurak is offline
Registered User
 
Join Date: Jan 2007
Posts: 4
Update ResultSet In Java Stored Procedure

I have the following Java Stored procedure which works fine, but what what I need to do is change one or more values in a field before I return the ResultSet. Can some show me an example of how to do that?

Thank You

Peter



public class SQL1131
{
public static void abend (String input, ResultSet[] rsout) throws
SQLException, Exception
{


int errorCode;

try
{

Connection con = DriverManager.getConnection("jdbc:default:connecti on");

String query = "SELECT * FROM STAFF WHERE JOB = ?";

PreparedStatement pstmt = con.prepareStatement(query);
pstmt.setString(1, input);
rsout[0] = pstmt.executeQuery();


}
catch (SQLException sqle)
{
errorCode = sqle.getErrorCode();
throw new SQLException( errorCode + " FAILED" );
}

}
}
Reply With Quote
  #2 (permalink)  
Old 04-20-11, 09:05
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
My first question is why you are doing such a simple procedure using java? Why not just make it a SQL stored procedure?

I assume you just want to transform some of the columns returned. You can do that in the query itself.

Andy
Reply With Quote
  #3 (permalink)  
Old 04-20-11, 10:12
pczurak pczurak is offline
Registered User
 
Join Date: Jan 2007
Posts: 4
Java SP

Quote:
Originally Posted by ARWinner View Post
My first question is why you are doing such a simple procedure using java? Why not just make it a SQL stored procedure?

I assume you just want to transform some of the columns returned. You can do that in the query itself.

Andy
Because the logic to get the values is a lot more complicated, I have get the values from our ERP System.
Reply With Quote
  #4 (permalink)  
Old 04-20-11, 10:31
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I have written numerous SQL Stored Procedures that perform some very complicated queries. SQL is a pretty powerful language.

Instead of dumbing down the query you want to perform, why don't you just show us in detail what you want to do?

Andy
Reply With Quote
  #5 (permalink)  
Old 04-20-11, 10:49
pczurak pczurak is offline
Registered User
 
Join Date: Jan 2007
Posts: 4
Java SP

The SQL DB2 Stored procedures can not call Business Functions in PeopleSoft, so I have to use Java and I have to return a ResultSet and some of the values are based on the return value from the Business Function.
Reply With Quote
  #6 (permalink)  
Old 04-20-11, 13:14
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
I suggest that you change your query to do the data modification in the query itself. For example, you could use CASE expressions.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On