Not able to connect SQL server in Groovy Not able to connect SQL server in Groovy selenium selenium

Not able to connect SQL server in Groovy


The JDBC connection is performed through global ClassLoader, so it does not see libs added to local ClassLoader.

You can add the driver jar globally to Control Tower tomcat:

$INSTALL_DIR/apps/webapps/tomcat/lib

For the logic to work in WorkFusion Studio, refer to the Eclipse guides on how to add external jar.

As a workaround (not recommended for production code), the following trick can be performed:

<script><![CDATA[    try {        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");    } catch (ClassNotFoundException expected) {        groovy.lang.GroovyShell.class.classLoader.addURL(new URL("http://clojars.org/repo/com/microsoft/sqlserver/sqljdbc4/4.0/sqljdbc4-4.0.jar"));    }]]></script>

More efficient way to execute queries is as following (will properly close the DB connection, etc.):

<database connection="jdbc:sqlserver://hostname:6501;DatabaseName=database"          jdbcclass="com.microsoft.sqlserver.jdbc.SQLServerDriver"          username="user" password="securepassword">    select first_name from actor</database>