# Running an Update Query From a Button/ SQL Jython problems

**URL:** <https://forum.inductiveautomation.com/t/running-an-update-query-from-a-button-sql-jython-problems/23486>\
**Category:** Ignition\
**Tags:** database\
**Created:** [March 20, 2019, 4:09pm UTC](https://forum.inductiveautomation.com/t/running-an-update-query-from-a-button-sql-jython-problems/23486 "2019-03-20T16:09:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ethanrendlen](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ethanrendlen](https://forum.inductiveautomation.com/u/ethanrendlen)\
**Post date:** [March 20, 2019, 4:09pm UTC](https://forum.inductiveautomation.com/t/running-an-update-query-from-a-button-sql-jython-problems/23486/1 "2019-03-20T16:09:25Z")

</div>

Hello,  
I am trying to do the SQL Update off of a EventHandler MousePressed. Click a button to add a entry in the MS SQL database.  
I want to update the database (which is one column at the moment, and the datatype is nvarchar), with my memory variable which is a string. The string is simply a label on the page which this component scripting is run. I have tried making a “test” string instead of trying to update with the property, no avail. I am having trouble getting jython to update anything in my SQL database (though if you turn on edit-able cells writing capability, it does work).

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/cd917e4154885e787196f2687f3fb053e1c1ca84.png)

I tried using MouseClicked instead and that did not help.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 20, 2019, 5:08pm UTC](https://forum.inductiveautomation.com/t/running-an-update-query-from-a-button-sql-jython-problems/23486/2 "2019-03-20T17:08:49Z")

</div>

The SQL Update helper there is basically useless. You’ll want an `actionPerformed` script that looks something like this (shown with ANSI SQL identifier quoting):

```auto
myLabel = event.source.parent.getComponent("MyLabelComponent")
system.db.runPrepUpdate("""Insert Into "ActiveList" ("SomeColumn") Values (?)""", [myLabel.text])

```

---

<div class="post-metadata">

**Author:** ![ethanrendlen](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ethanrendlen](https://forum.inductiveautomation.com/u/ethanrendlen)\
**Post date:** [March 20, 2019, 5:28pm UTC](https://forum.inductiveautomation.com/t/running-an-update-query-from-a-button-sql-jython-problems/23486/3 "2019-03-20T17:28:26Z")

</div>

> [@pturmel](#):
>
> myLabel = event.source.parent.getComponent("MyLabelComponent") system.db.runPrepUpdate("""Insert Into "ActiveList" ("SomeColumn") Values (?)""", [myLabel.text])

Thank you very much PTurmel.  
This is my new code:

myLabel = event.source.parent.getComponent('Label')  
system.db.runPrepUpdate("""Insert Into ActiveList ("JobNum") Values (?)""", [myLabel.text])

#################### It seems that your triple quotes do the trick to make the script editor happy and not throwing errors, however, it does when it compiles. I get:

caused by Exception: Error executing system.db.runPrepUpdate(Insert Into ActiveList ("JobNum") Values (?), [522756-8-1], , , false, false)  
caused by GatewayException: SQL error for "Insert Into ActiveList ("JobNum") Values (?)": ERROR: relation "activelist" does not exist  
Position: 13  
caused by PSQLException: ERROR: relation "activelist" does not exist  
Position: 13

I tried "ActiveList" with quotes and without, and I get the same error. I can browse this table from the DB browser so I know it is there.

---

<div class="post-metadata">

**Author:** ![ethanrendlen](https://avatars.discourse-cdn.com/v4/letter/e/77aa72/32.png) [@ethanrendlen](https://forum.inductiveautomation.com/u/ethanrendlen)\
**Post date:** [March 20, 2019, 5:39pm UTC](https://forum.inductiveautomation.com/t/running-an-update-query-from-a-button-sql-jython-problems/23486/4 "2019-03-20T17:39:16Z")

</div>

My default database was set wrong and I did not get it to respond to specifying the database. Just had to change the default. FIXED
