I have tried the following code and it cannot find the driver:
def sqlTest(): # does not work, annot find jdbc driver and stops.
from com.ziclix.python.sql import zxJDBC
url = "jdbc:sqlserver://localhost\SQLEXPRESS"
user = "sa"
password = "password"
driver = "com.microsoft.sqlserver.jdbc"
mysqlConn = zxJDBC.connect(url, user, password, driver)
mysqlConn = con.cursor()
mysqlConn.execute("SELECT * FROM deviationV6")
print user
for a in mysql.fetchall():
print a
I am looking to automate the creation of a SQL table based on reading in a Word text document. I know I can create a file to run in management studio, but it would be more elegant to do it from within the script.
I get errors with “Create” in the supplied functions.
Ignition doesn’t use the system’s installed packages. Just its own, plus any configured by third-party modules. JDBC drivers are only accessible through the system.db.* functions, as they are loaded privately (isolated java classloaders) in the gateway, and only in the gateway.
I don’t think you’re going to get zxJDBC to work under Ignition.
caused by Exception: Error executing system.db.runQuery(CREATE TABLE formOne, , )
caused by GatewayException: Incorrect syntax near 'formOne'.
caused by SQLServerException: Incorrect syntax near 'formOne'.
You are using the wrong function. Queries called with system.db.runQuery() must return a result. Update/Insert queries and data definition statements generally don’t. Use system.db.runUpdateQuery() instead. If you need to pass values to these queries, use runPrepQuery() and runPrepUpdate() instead.
Personally I love examples for how to do things. On the Ignition Exchange there is an ad hoc trend template for Vision. It is set up to create tables if they don’t exist. If you open the template and look at the “Add Annotation” button, the script under mouse pressed uses system.db.runPrepUpdate() to create a table based on the database type which is found using an expression from and internal template property. There are examples for mySQL, msSQL, Oracle and Postgres databases. I’m assuming they all work, I’ve only use it on mySQL and msSQL.
In my case, I have some complex code I'm inheriting which has DB stuff but no other system.* calls through Ignition. If I could do something like what the original poster is trying to do, I could run the code in Eclipse and have a full step-by-step debugger and object viewer, unlike if I run it in Ignition.
Getting your system.db.* function implementations outside Ignition to behave sufficiently like Ignition's actual functions will be a considerable chore. But please blaze this trail for us. It might be valuable.