web stats
Javawriter DB query into local variables - Mirth Community

Go Back   Mirth Community > Mirth Connect > Development

Reply
 
Thread Tools Display Modes
  #1  
Old 01-31-2013, 07:59 AM
appsbyaaron's Avatar
appsbyaaron appsbyaaron is offline
Mirth Guru
 
Join Date: Nov 2011
Location: Florida, USA
Posts: 377
appsbyaaron is on a distinguished road
Default Javawriter DB query into local variables

I have a Javawriter connector that is running an Oracle query to pull back 2 fields from a table. How do I put those two values into a variable (channel map)?

I've tried the following:

var var_batch_count;
var var_error_text;
var local_batch_id = channelMap.get('temp_batch_id');

//Call CHIRP HL7 Function Part 1
var temp_SQL = 'SELECT COUNT (se.batch_id) as var_batch_count, se.ERROR_TEXT as var_error_text FROM h33_hl7_send_error se WHERE se.batch_id = ' + local_batch_id + ' AND TRUNC (se.received) = TRUNC (SYSDATE - 1) AND se.message_type_received = ' + 'ACK' + ' AND se.is_error = ' + 'Y' + 'GROUP BY se.batch_id, se.ERROR_TEXT';
var temppw = 'secret password';
var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('connection string data');

var result = dbConn.executeCachedQuery(temp_SQL);

var_batch_count = dbConn.executeCachedQuery(temp_SQL.var_batch_count);
var_error_text = dbConn.executeCachedQuery(temp_SQL.var_error_text);

channelMap.put('temp_total_count',var_batch_count) ;
channelMap.put('temp_error_count',var_error_text);
Reply With Quote
  #2  
Old 01-31-2013, 09:31 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,119
narupley is on a distinguished road
Default

Quote:
Originally Posted by appsbyaaron View Post
var_batch_count = dbConn.executeCachedQuery(temp_SQL.var_batch_count);
var_error_text = dbConn.executeCachedQuery(temp_SQL.var_error_text);
What is that code trying to accomplish? The executeCachedQuery method takes in a string (temp_SQL.var_batch_count will probably return undefined) and returns a CachedRowSet. From there you need to iterate through it just as you would a ResultSet, using next() and the various getter methods.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 01-31-2013, 09:43 AM
appsbyaaron's Avatar
appsbyaaron appsbyaaron is offline
Mirth Guru
 
Join Date: Nov 2011
Location: Florida, USA
Posts: 377
appsbyaaron is on a distinguished road
Default

thanks Nick. I think the real issue here is the password to the server. it contains a '(' and I've had issues trying to get a valid connection to the database using this method. When I try to simply connect and end the connection it still fails the channel.

I even tried to split the select into 2 separate ones but it still won't work.

thanks anyway.
Reply With Quote
  #4  
Old 01-31-2013, 09:46 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,119
narupley is on a distinguished road
Default

Quote:
Originally Posted by appsbyaaron View Post
thanks Nick. I think the real issue here is the password to the server. it contains a '(' and I've had issues trying to get a valid connection to the database using this method. When I try to simply connect and end the connection it still fails the channel.

I even tried to split the select into 2 separate ones but it still won't work.

thanks anyway.
Whether or not the password is correct, the following code is incorrect:

Code:
var_batch_count = dbConn.executeCachedQuery(temp_SQL.var_batch_count);
var_error_text = dbConn.executeCachedQuery(temp_SQL.var_error_text);
Can you post the full error you're seeing here?
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #5  
Old 02-06-2013, 05:32 AM
appsbyaaron's Avatar
appsbyaaron appsbyaaron is offline
Mirth Guru
 
Join Date: Nov 2011
Location: Florida, USA
Posts: 377
appsbyaaron is on a distinguished road
Default

Quote:
Originally Posted by narupley View Post
The executeCachedQuery method takes in a string (temp_SQL.var_batch_count will probably return undefined) and returns a CachedRowSet. From there you need to iterate through it just as you would a ResultSet, using next() and the various getter methods.
I suck at life. I'm getting the CachedRowSet but am having issues with the iteration. Do you have an example?
Reply With Quote
  #6  
Old 02-06-2013, 06:18 AM
appsbyaaron's Avatar
appsbyaaron appsbyaaron is offline
Mirth Guru
 
Join Date: Nov 2011
Location: Florida, USA
Posts: 377
appsbyaaron is on a distinguished road
Default

Nevermind! I GOT IT!! Thank you all!!
Reply With Quote
Reply

Tags
channelmap, javawriter, oracle, sql

Thread Tools
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 On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 10:18 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation