Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Steps to create a External Relational Database Thing and update configuration at Runtime in ThingWorx

No ratings
  • How to input Database User Credentials at RunTime.

This Blog considers that you have already imported the Database Extension and Configured the Thing Template. If you have not done this already please see Steps to connecting to your Relational Database first.


  1. Create a Database Thing template with correct configuration.
    • Example configuration for MySql Database:
      • jDBCDriverClass: com.mysql.jdbc.Driver
      • jDBCConnectionURL: jdbc:mysql://<DatabaseNameHere>?allowMultiQueries=true
      • connectionValidationString: SELECT NOW()
      • maxConnections: 100
      • userName: <DataBaseUserNameHere>
      • password: <DataBasePasswordHere>
  2. Create any Generic Thing and add a service to create thing based on the Thing template created in Step 1.
    • Example:
      • // NewDataBaseThingName is the String input for name the database thing to be created.

        // MySqlServerUpdatedConfiguration is the Thing template with correct configuration

        var params = {

             name: NewDataBaseThingName /* STRING */,

             description: NewDataBaseThingName /* STRING */,

            thingTemplateName: "MySqlServerUpdatedConfiguration" /* THINGTEMPLATENAME */,

            tags: undefined /* TAGS */


        // no return


  3. Add code to enable and then restart the above thing using EnableThing() and RestartThing() service.
    • Example
      • Things[NewDataBaseThingName].EnableThing();


  4. Test and confirm that the Database Thing services runs as expected.
  5. Now Create a DataShape with following Fields:
    • jDBCDriverClass: STRING
    • jDBCConnectionURL: STRING
    • connectionValidationString: STRING
    • maxConnections: NUMBER
    • userName: STRING
    • password: PASSWORD
  6. Now in the Generic Thing created in Step 1 add code to update the configuration settings of DataBase Thing.
    • Make sure JDBC Driver Class Name should never be changed.
    • If different database connection is required use different Thing Template.
    • Also, add code to restart the DataBase Thing using RestartThing() service.
    • Example:
            • var datashapeParams = {

                  infoTableName : "InfoTable",

                  dataShapeName : "DatabaseConfigurationDS"

            • // CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(DatabaseConfigurationDS)

              var config = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(datashapeParams);

              var passwordParams = {

                      data: "DataBasePasswordHere" /* STRING */


            • // DatabaseConfigurationDS entry object

              var newEntry = new Object();

              newEntry.jDBCDriverClass= "com.mysql.jdbc.Driver"; // STRING

              newEntry.jDBCConnectionURL = "jdbc:mysql://<DatabaseNameHere>?allowMultiQueries=true"; // STRING

              newEntry.connectionValidationString = "SELECT NOW()"; // STRING

              newEntry.maxConnections = 100; // NUMBER

              newEntry.userName = "DataBaseUserNameHere"; // STRING

              newEntry.password = Resources["EncryptionServices"].EncryptPropertyValue(passwordParams); // PASSWORD


            • var configurationTableParams = {

              configurationTable: config /* INFOTABLE */,

              persistent: true /* BOOLEAN */,

              tableName: "ConnectionInfo" /* STRING */


            • // ThingNameForConfigurationUpdate is the input string for Thing Name whose configuration needs to be updated.

              // no return



    • Test and confirm that the Database Thing services runs as expected.

    @ankigupta I am getting an error saying the configuration structure does not match.

    Do not  execute this line until configuration is set for that thing

    Version history
    Last update:
    ‎Mar 16, 2017 11:41 PM
    Updated by:
    Labels (2)