Hi,
I am new to groovy and OO programming. I have to develop a groovy script to connect to an external Microsoft sql server by executing a post function in JIRA. I am using script runner plugin for the execution of script.
After an exhaustive study on various posts related to groovy, I developed 2 scripts as below, however, none of then is working.
Script 1:
-----------------------------------
import groovy.sql.Sql
import java.sql.Driver
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
def sql = Sql.newInstance("jdbc:sqlserver://servername:1433/Valid_DB_Name", "Valid user", "valid password", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
------------------------------------
Error: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
------------------------------------------------------------------------------------------------------------------------------------------
Script 2:
-----------------------------------
import groovy.sql.Sql
import java.sql.Driver
this.class.classLoader.rootLoader.addURL(new URL("file:///C:/TEMP/sqljdbc4.jar"))
import groovy.sql.Sql
import java.sql.Driver
def sql = Sql.newInstance("jdbc:sqlserver://servername:1433/Valid_DB_Name", "Valid user", "valid password", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
------------------------------------
Error: java.lang.NullPointerException: Cannot invoke method addURL() on null object
------------------------------------------------------------------------------------------------------------------------------------------
I have tried various ways to fix it, however, no success. It seems, I am not able to set the classpath correctly here. I have declared it as an environment variable even (CLASSPATH=.;C:/TEMP/sqljdbc4.jar"). But, results is still the same.
Please help. I am stuck here for more than a week now
.
Best regards,
Nishant