Is there a way I can access the DatasourceManager interface from a script? I'd like to be able to grab a jdbc connection in a script from an established Connection in the gateway so I can perform some tasks that the standard system.db doesn't handle (specifically Snowflake JDBC downloadStream to access staged files). I've been able to do this manually in code with java.sql.Connection class but that means providing the entire connection string and authentication elements in my code.
Attempts to so call the interface method fail because their is no public constructor and calls to the methods are expecting 'self' argument
INFO | jvm 1 | 2025/04/11 12:15:59 | TypeError: getDatasource(): expected 2 args; got 1
Thanks
Ignition's datasource manager is available from a gateway context, like that delivered from my system.util.toolkitCtx(), but it isn't going to help you. Ignition runs connection pooling with a generic vanilla JDBC layer around the actual JDBC connections, plus the real connections are buried in isolated classloaders. You might succeed with java reflection. Good luck. (I've poked at that. It is fragile.)
Thank you! This was just what I needed. Believe it or not it worked . Here is a snippet
context = system.util.toolkitCtx()
dbm = context.getDatasourceManager()
ds = dbm.getDatasource("DBName")
connection = ds.getConnection()
statement = connection.createStatement()
#Create Temporary Stage
statement.executeUpdate(createstage)
#Execute COPY INTO test
statement.executeUpdate(copycmd)
#Create Stream
inputstream = connection.unwrap(net.snowflake.client.jdbc.SnowflakeConnection).downloadStream(stagename,filename,False)
#Download File
system.perspective.download(filename,inputstream)
1 Like