Announcement

Collapse
No announcement yet.

Database Writer / Database Reader problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Database Writer / Database Reader problem

    I was just testing the database writer/database reader. I have the following code for source connector.

    Code:
    var dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:«»sqlserver://xxx.xxx.xx.xx:«»xxxx/LocalDB','xx','xxxx');
    var result = dbConn.executeCachedQuery("Exec sp_test_S"«»);
    var temp = "";
    
    while(result.next())
    {
    temp = result.GetString(0).ToString() + ",";  
    }
    temp = temp.Substring(0, temp.Length - 1);
    dbConn.close();
    channelMap.put("Results", temp);
    return temp;
    And my destination I had a Database Writer and the following code

    Code:
     var dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:«»sqlserver://xxx.xxx.xx.xxx:1433/LocalDB','sa','xxxx');
    
    var expression = "Insert into tmpDev(TempVisitID) values(" + channelMap.get("Results"«») + "«»)";
    
    var result = dbConn.executeUpdate(expression);
    dbConn.close();
    I am not able to insert the record into the tmpdev table using the above logic. Is something wrong with the code? Your help will be appreciated.

  • #2
    Reatabase Writer / Database Reader problem

    You don't have access to the channelMap from the source connector (there isn't a valid message yet), so whatever data you need to pass needs to be included in the return value of the database reader.

    Does the message successfully process? (No errors on the dashboard?) Check the message viewer and please let me know the contents of "Raw Data".

    If you return a result set, list or hash map, Mirth will automatically convert your data into a valid XML payload. You can extract values from the XML in your transformer and then place into the channel map for use on the destination Database writer.

    You can also return your own string data in the Database Reader, but it must be a valid XML format.

    -Chris
    Chris Lang

    Comment


    • #3
      Reatabase Writer / Database Reader problem

      Hi Chris,

      Thanks for the response. I removed the channel map and I just tried to return the temp value. The temp value just contains a string like '100, 101, 102, 103'. I am able to execute the store procedure and get the data into the temp value but I cannot see the temp variable in the message template area. How do I access the temp value in the destination transformer? Here is my code to the source connector that worked fine.

      Code:
      var dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:«»sqlserver://xxx.xx.xx.xxx/localdb','xx','xxxxx');
      var result = dbConn.executeCachedQuery("Exec usp_temp_s"«»);
      var temp = "";
      result.next();
      while(result.next())
      {
      temp = temp + result.getInt(1).toString() + ",";  
      }
      temp = temp.substring(0, temp.length - 1);
      logger.error("Temp Value after "  + temp);
      dbConn.close();
      return temp;
      I am able to get the values from the database into my temp variable but I cannot see the temp variable in the mapping tree area. How do I access it in the destination transfomer? Thanks for all the help Chris.

      Comment


      • #4
        Is this still true that you can return a Map from a DB reader? I have just been trying this and I get an error: "Got a result of: {my entire map listed here}".

        The error references JdbcMessageReceiver and when I took a look at the specified line (246) I see implementations for List but not Map.

        Thanks for any light you can shed on this.

        Comment

        Working...
        X