Beginning with CWMS/HEC-RTS 3.4, the CWMSjy scripting API supports both read and write operations, replacing the legacy DBAPI.py.

This guide walks you through updating your script to use CWMSjy.

Step 1: Open Your Script

  1. Identify the script you need to edit and open it in your script editor.

Step 2: Remove Old DBI Connection Lines

  1. Locate the lines where the script connects to the database using cwms.dbi. You'll typically see something like this: 
    cwms.dbi.ConnectUsingUrl=jdbc:oracle:thin:@
    cwms.dbi.OfficeId=
    CODE
  2. Comment out or delete these lines (lines 8-9 in the example below).

    Original Code with DBAPI.py

    #----------------#
    DBI properties #
    #----------------#
    ###
    Database connection specs
    
    ###
    #cwms.dbi.ConnectUsingUrl=jdbc:oracle:thin:@XXX.XX.XXX.XX:XXXX/G6CWMSP1
    #cwms.dbi.OfficeId=NWDM
    from hec.heclib.dss import HecDss, DSSPathname
    from javax.swing import JOptionPane
    from hec.dataTable import HecDataTableToExcel
    from hec.heclib.util import HecTime
    from hec.script import Plot
    #from cwms import cwms
    #from hec.cwms import CWMSjy
    import time, thread, wcds, java, javax, os, operator, hec, traceback, string, RADARAPI, CWMSjy, DBAPI, sys
    
    #######################
    Get Database Connection ##
    
    #######################
    db = DBAPI.open()
    db.setTimeZone('UTC')
    
    ############################################
    CODE

Step 3: Replace the DBAPI.open( ) Call

  1. Look for this line:
    db = DBAPI.open()
    CODE
  2. Comment it out or delete it and replace it with:
    db = CWMSjy.open("CWBI TEST OR YOUR OFFICE CDA INSTANCE HTML", "YOUR OFFICE")
    CODE
  3. Your updated code should look something like this:

    New Code with CWMSJy

    #----------------#
    DBI properties #
    
    #----------------#
    
    ###
    Database connection specs
    
    ###
    #cwms.dbi.ConnectUsingUrl=jdbc:oracle:thin:@XXX.XX.XXX.XX:XXXX/G6CWMSP1
    #cwms.dbi.OfficeId=NWDM
    from hec.heclib.dss import HecDss, DSSPathname
    from javax.swing import JOptionPane
    from hec.dataTable import HecDataTableToExcel
    from hec.heclib.util import HecTime
    from hec.script import Plot
    import time, thread, wcds, java, javax, os, operator, hec, traceback, string, RADARAPI, CWMSjy, DBAPI, sys
    
    #######################
    Get Database Connection ##
    
    #######################
    #db = DBAPI.open()
    db = CWMSjy.open("https://cwms-data-test.cwbi.us/cwms-data/", "MVS")
    db.setTimeZone('UTC')
    
    ############################################
    CODE

Step 4: Save and Run Your Script

After making these changes, save your script and run it to verify successful connection and operation using CWMSjy.