web stats
Mirth Connect & SQL Server resultset - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2015, 03:14 AM
sdpillar sdpillar is offline
Mirth Newb
 
Join Date: Mar 2013
Posts: 14
sdpillar is on a distinguished road
Default Mirth Connect & SQL Server resultset

My Mirth transformer is querying a sql server db table. I need to loop through the returned resultset.

The following is my code:

var dbConn;
dbConn = DatabaseConnectionFactory.createDatabaseConnection ('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sql server://localhost:1433/MyDatabase','admin','admin');
var queryString = "select UUID, UniqueId from MyDocuments where UniqueID = '1.2.1.4.4.1.4.7.4.6.0'";
logger.info("Query - " + queryString);
result = dbConn.executeCachedQuery(queryString);

while(result.next())
{
var uuid = result.getString(1);
var uniqueId = result.getString(2);
logger.info("Document info - " + uuid + " - " + uniqueId);
}


The log is showing as:

"Document info - urn:uuid:0701c757-4fcb-4946-981d-e28bf1422164 - javax.sql.rowset.serial.SerialClob@45353152"

So the read of the first column in the resultset is ok, but no idea where the 'javax.sql.rowset.serial.SerialClob@45353152' is coming from.

Normally I work with postgres databases but this is the first time I have worked with SQL server in Mirth.

Any help/guidance much appreciated
Reply With Quote
  #2  
Old 02-11-2015, 04:29 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

I've always used the names

var uuid = result.getString('UUID');
var uniqueId = result.getString('UniqueId');
Reply With Quote
  #3  
Old 02-11-2015, 05:39 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,111
narupley is on a distinguished road
Default

That column is a CLOB, not a string. You can call getClob instead, then getCharacterStream() to get a Reader for it. If you want an easy way to convert that to a String, use IOUtils.
__________________
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
  #4  
Old 02-11-2015, 11:38 PM
sdpillar sdpillar is offline
Mirth Newb
 
Join Date: Mar 2013
Posts: 14
sdpillar is on a distinguished road
Default

Thanks for the replies.

I resolved it, with the following:

clob = result.getClob(1);
clobLength = clob.length();
uniqueId = clob.getSubString(1,clobLength);
Reply With Quote
Reply

Tags
error, query, results, sql server

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 01:34 PM.


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