Skip to main content

developerWorks >  WebSphere  >  Forums  >  IBM WebSphere Portlet Factory - Databases and Data Sources  >  developerWorks

How to return message from DB2?    Point your RSS reader here for a feed of the latest messages in this thread


     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
This question is answered.

Permlink Replies: 5 - Pages: 1 - Last Post: Nov 10, 2009 11:00 AM Last Post By: cdub Threads: [ Previous | Next ]
cdub

Posts: 10
Registered: Oct 21, 2009 11:59:41 AM
How to return message from DB2?
Posted: Nov 04, 2009 02:46:41 PM
 
Click to report abuse...   Click to reply to this thread Reply
I am running UPDATE queries and I am trying to display a message after it is successful. In DB2 command line editor a successful message shows the query that was ran and then a message below it saying: "DB20000I The SQL command completed successfully."

I would like to know how to get WPF to display a message like this if possible on a separate page. The only problem I see right now why I can't get this message is because I am using SQL Call builders and Service Operation for the all my queries. The Service Operation for the UPDATE query under the Operation Results section doesn't allow me to return results.
bosox

Posts: 430
Registered: Aug 08, 2006 03:26:03 PM
Re: How to return message from DB2?
Posted: Nov 06, 2009 01:39:36 PM   in response to: cdub in response to: cdub's post
 
Click to report abuse...   Click to reply to this thread Reply
I don't think I have a really great answer for you. One idea I had for a work around though was that you could wrap the SQL Call for your update in a method. In your method, put the call into a try/catch block. You could then have this mehtod return a simple XML value that has text in it that is either a success or failure method. The message could be set to success initially and then set to failure if the code gets into the catch. Then you would update your Service Operation to call this method instead of calling the SQL Call directly. Also update the Service operation to return the simple XML value.
kevintap

Posts: 329
Registered: Mar 08, 2005 11:09:39 AM
Re: How to return message from DB2?
Posted: Nov 06, 2009 02:03:49 PM   in response to: bosox in response to: bosox's post
 
Click to report abuse...   Click to reply to this thread Reply
bosox makes a good suggestion; you can wrap your SQL Call builder with a Method that returns a status message or boolean value. Another technique that I've used in the past is to wrap your SQL statement with a SELECT clause like this:
SELECT
  COUNT(*) AS ROW_COUNT
FROM NEW TABLE (
  UPDATE
    tablename
  SET
    field=?
  WHERE
    key=?
)

This makes your UPDATE statement actually return a row count of the number of rows that were updated in the table. The "NEW TABLE" is a SQL keyword that provides a representation of subset of rows updated by the UPDATE.
DGawron

Posts: 630
Registered: Aug 15, 2006 10:31:49 AM
Re: How to return message from DB2?
Posted: Nov 06, 2009 03:52:24 PM   in response to: kevintap in response to: kevintap's post
 
Click to report abuse...   Click to reply to this thread Reply
You mentioned that you were performing multiple updates. If these are done as part of a transaction, then you may want to look at this thread: https://www.ibm.com/developerworks/forums/thread.jspa?messageID=13963713&#13963713. It has a sample model showing how to get an update count without having to rewrite your SQL.
cdub

Posts: 10
Registered: Oct 21, 2009 11:59:41 AM
Re: How to return message from DB2?
Posted: Nov 09, 2009 12:01:26 PM   in response to: DGawron in response to: DGawron's post
 
Click to report abuse...   Click to reply to this thread Reply
Thanks for the replies. Except I have some questions about your suggestions.
1. If I were to wrap my SQL Call with a SELECT clause, where does NEW TABLE come from? Do I use it exactly like you have it typed?

2. DGawron, I have looked at the getUpdatedCount.Model before. The question I have is with the Method Builder. In the method builder you have several arguments listed. Where do they come from? And as you know, I am using three update statement on three different tables. For the update count variable and text pointing to the variable, does that mean I need to create two more variables and text builders? And then wouldn't that mean I would need to create two more methods as well?

And for both of you, I am asking all this cause on my first page I have two input fields (newHostName and oldHostName) then a submit button. I am replacing the oldHostName with the newHostName and assigning the variables from the inputs and connecting them through the DataServices(If that makes sense). I also have a page2 that I created with a span tag for the updated count. So for my main(Action List) I have page1 listed. For my button builder I have another Action List that has all the Variables assigned to the inputs and listed below that are the all the Dataservices and then page2. Thats what I have so far except I can't get the updated count to display.
cdub

Posts: 10
Registered: Oct 21, 2009 11:59:41 AM
Re: How to return message from DB2?
Posted: Nov 10, 2009 11:00:49 AM   in response to: cdub in response to: cdub's post
 
Click to report abuse...   Click to reply to this thread Reply
Thanks again guys. I believe I have figured it out. Since I am updating three tables, I had to create three methods, variables and text builders. Basically I followed along the GetUpdateCount.Model and it worked. Now I need to work on validation so I might be asking a few questions on how and what to put in a validation as an LJO.

Thanks,
Corey
 Tags
Help

Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular type of content or application that you're viewing.

My tags shows your tags for this particular type of content or application that you're viewing.

 

MoreLess 


Point your RSS reader here for a feed of the latest messages in all forums