Search This Blog

Monday, February 13, 2023

MAXIMO : Run SQL statements from Automation Scripts

This article details  Maximo automation script  needing to execute plain SQL statements instead of Maximo Mbo and MboSet related methods.


Broadly there are two way's to handle SQL statement exeuction , first is you can simply follow standard java.sql package and use respective connection and allied objects and the next which is recommended one is to use maximo DBShortcut class from framework which supports connection pool optimized way in terms of performance/resource usage and clean up aspects.

Below are sample code snippet which can show how to use these two approaches

1. JDBC Connection:

  from psdi.security import UserInfo

from psdi.server import MXServer
 
vsql = "update workorder set priority='1'
         where wonum=1002"
 mxserver = MXServer.getMXServer()
conKey = mxserver.getSystemUserInfo().getConnectionKey()
cnx = mxserver.getDBManager().getConnection(conKey)
stmt = cnx.createStatement()
stmt.executeUpdate(vsql)
 
stmt.close()
cnx.commit()
mxserver.getDBManager().freeConnection(conKey)

2. DBShortcut Class:

  from psdi.mbo import DBShortcut, SqlFormat

from psdi.server import MXServer
 
vsql = "update workorder set priority='1' where wonum=1002"
 
mxserver = MXServer.getMXServer()
conKey = mxserver.getSystemUserInfo().getConnectionKey()
dbs = DBShortcut()
dbs.connect(conKey)
 
sqf = SqlFormat(vsql)
dbs.execute(1, sqf)
dbs.commit()
dbs.close()

MAXIMO - DBC Script Guide

 Here I am sharing IBM guide for DBC.

This will be helpful DevOps automation towards most of maximo configuration migrations put under typical pipeline tools like Jenkins.


DBC XML Format.pdf