简体   繁体   中英

change the connector type from javascript to Database Reader in javascript mode mirth?

When change the connector type from javascript to Database Reader in javascript mode, I recivied an error

Received invalid list entry in channel expected Map

how to use List<Map<String, Object>> or ResultSet instead of java.util.ArrayList() .

var dbConn = globalMap.get('tes55');

    if (dbConn == null || !dbConn.getConnection().isValid(1))
    {
        var dbConn = DatabaseConnectionFactory.createDatabaseConnection('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:@10.123.117.203:1521/UAT','intg','intg');
        dbConn.getConnection().setNetworkTimeout(java.util.concurrent.Executors.newFixedThreadPool(1), 30000);
        globalMap.put('tes55',dbConn);
    }
           dbConn.setAutoCommit(false);
    try{
 var x="select IH_HL7_OUM_ID, MESSAGE_ID, frame_text from ideal.EHS_Acks_MESSAGES s WHERE (message_type = 'S12' or message_type = 'S15' or message_type = 'A04' or message_type = 'A11') and rownum<=2";    
 var rs=dbConn.getConnection().createStatement().executeQuery(x);
 var msgs=new java.util.ArrayList();
while(rs.next()){
          var IH_HL7_OUM_ID=rs.getString("IH_HL7_OUM_ID");
          var MESSAGE_ID =rs.getString("MESSAGE_ID");
          var frame_text =rs.getString("frame_text");

          // logger.info(MESSAGE_ID);
           //logger.info(IH_HL7_OUM_ID);
            // logger.info(frame_text);
           msgs.add(frame_text);

 //map.set(frame_text);

var query="update ih_hl7_outbound_messages  set IS_SENT= 2 where  MESSAGE_ID ="+MESSAGE_ID+" and id<="+IH_HL7_OUM_ID;
var update=dbConn.executeUpdate(query);
//logger.info(update);
dbConn.commit();

//logger.info(query);


              }

        rs.close();
        return msgs;
    } 
catch(exp)
{
     returned_response = ResponseFactory.getQueuedResponse("Failed to execute the query "  + "\nReason: " + exp.message); 
     logger.error(exp.message);
     alerts.sendAlert("\n\nMessage ID: " +$('msgID') + "\nMessage type: " +$('msgtype')+"\nException: "+exp.message +"\nMessage :\n"+msgs.add(frame_text));
     try{dbConn.close();}catch(ignore){logger.info("Close Connection: "+ignore.message);}
}
finally
{
    try{rs.close();}catch(ignore){logger.info("Close Cursor: "+ignore.message);}
}

return returned_response;

Mirth Database Reader will ease you data fetching process. We need not write many codes and complicate in the source listener 在此处输入图片说明

You can see URL specified you can select the DB type you want, in your case it's oracle, automatically the URL will be filled. provide your username and password to access the DB.

click on "select" button over the SQL text area this will open a pop-up displaying all the tables to be selected. once you click tick on the tables you want. The code will be generated automatically.

If you want to do join or perform any query operation you can do that there in the generated code on the text area content.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM