Running an Update Query From a Button/ SQL Jython problems

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).

I tried using MouseClicked instead and that did not help.

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):

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.

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

1 Like