web stats
Mirth Connect & SQL Server resultset - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 02-11-2015, 04: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 = ''";
logger.info("Query - " + queryString);
result = dbConn.executeCachedQuery(queryString);

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
Old 02-11-2015, 05: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

I've always used the names

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

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
Old 02-12-2015, 12:38 AM
sdpillar sdpillar is offline
Mirth Newb
Join Date: Mar 2013
Posts: 14
sdpillar is on a distinguished road

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

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 08:52 PM.

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