How to UPDATE a SQL server database via a MID Server from a script

bpolo
Tera Guru

We have a script where we insert an ECC queue record to UPDATE a SQL table. When we set the SQL query to be a SELECT statement it works. But when we change the SQL statement to be an UPDATE we get the following error: 

SQLException: Statement.executeQuery() cannot issue statements that do not produce result sets.
 
It seems that the statement that should be executeUpdate(). What field needs to be set up on the ECC queue record to make it say executeUpdate instead executeQuery() ?  Thanks in advance!
1 ACCEPTED SOLUTION

bpolo
Tera Guru

We have found a solution - This is the parameter that we required to get the UPDATE of the SQL table to execute successfully: 

<parameter name= "work" ><update table = "alerts.status" where = "ServerName %= 'NCOMS' AND ServerSerial=3935" ><Agent>ServiceNow - INC10020</Agent><URL>http://Macintosh-9.local:8080/glide/incident.do?sys_id=17a31f380a0a0bae0048ca875c8891d0</URL><Severity quoted = "false" >3</Severity><Acknowledged quoted = "false" >0</Acknowledged></update></parameter>

View solution in original post

6 REPLIES 6

bpolo
Tera Guru

Thanks for the response! So the way we are doing this is via an onAfter script of a transform map. In the script we hard-code the payload and insert a record on the ECC queue. This will go via the MID Server to update the SQL database. The issue is that when the SQL statement is a "SELECT" it works, but when it is an "UPDATE" it does not work. Please advise.  

Bert_c1
Kilo Patron

@bpolo 

 

I put your thread title in the search on google.com. Try that, the AI response discusses what you seem to want.  also, post on the thread I provided a link to. Folks there may be able to help. I do not practice what you want to achieve. I suspect there are permission problems on the SQL server where a query works but not updating a record in the database works. There should be some error/logs there showing the problem.

 

On the google response, click "Dive deeper in AI mode" examples are shown.

Ajay_Chavan
Kilo Sage
ECC Queue Record Configuration:
Table: ecc_queue
- agent: [your_mid_server]
- topic: [your_topic] 
- name: "executeUpdate"
- payload: [your UPDATE SQL statement]
- source: [source_identifier]
Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****