I’m getting an error message when I’m running my code to update a table in my SQL db.
The Code is:
[code]string = event.source.parent.getComponent(‘Group’).getComponent(‘Text Field’).text
string2 = event.source.parent.getComponent(‘Group’).getComponent(‘Text Field 1’).text
string3 = event.source.parent.getComponent(‘Group’).getComponent(‘Text Field 3’).text
string4 = event.source.parent.getComponent(‘Group’).getComponent(‘Text Field 2’).text
string5 = event.source.parent.getComponent(‘Group’).getComponent(‘Text Area’).text
number = event.source.parent.getComponent(‘Group’).getComponent(‘Numeric Text Field’).intValue
table = event.source.parent.getComponent(‘Table’)
tableName = “workorders”
db = “DB”
Create the insert query
insertQuery = “”“INSERT INTO [%s] ([string], [string2], [string3], [string4], [string5], [number])
VALUES (’%s’, ‘%s’, ‘%s’, ‘%s’, ‘%s’, %d)”"" % (tableName, string, string2, string3, string4, string5, number)
Insert the record in the database table
system.db.runUpdateQuery(insertQuery,db)
Refresh the table data
system.db.refresh(table, “data”)[/code]
The error message is:
Traceback (most recent call last):
File “event:actionPerformed”, line 16, in
VALUES ('Test', '8/26/2015', 'SQL Update', 'Office Work', 'Syntax Error', 55), DB, , false)
java.lang.Exception: java.lang.Exception: Error executing system.db.runUpdateQuery(INSERT INTO [workorders] ([string], [string2], [string3], [string4], [string5], [number])
VALUES ('Test', '8/26/2015', 'SQL Update', 'Office Work', 'Syntax Error', 55), DB, , false)
caused by Exception: Error executing system.db.runUpdateQuery(INSERT INTO [workorders] ([string], [string2], [string3], [string4], [string5], [number])
VALUES ('Test', '8/26/2015', 'SQL Update', 'Office Work', 'Syntax Error', 55), DB, , false)
caused by GatewayException: SQL error for "INSERT INTO [workorders] ([string], [string2], [string3], [string4], [string5], [number])
VALUES ('Test', '8/26/2015', 'SQL Update', 'Office Work', 'Syntax Error', 55)": You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[workorders] ([string], [string2], [string3], [string4], [string5], [number])
’ at line 1
caused by MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[workorders] ([string], [string2], [string3], [string4], [string5], [number])
’ at line 1
Ignition v7.7.5 (b2015071516)
Java: Oracle Corporation 1.8.0_51
Any thoughts?