Forum Discussion

Dipin's avatar
Dipin
New Contributor
4 years ago
Solved

Data Base Connection using Groovy Script in SOAP UI

I am trying to connect to Data base and getting the below error.

 

Executed the below query and getting some exception in error log.:

 

QUERY :

import groovy.sql.Sql
//import groovy.sql.*
import java.sql.SQLException
import oracle.jdbc.driver.*
//import com.eviware.soapui.support.GroovyUtils.*

// Set up database connection properties.
def url = '' /* IMPORTANT: must start with jdbc:mysql:// */
def user = ''
def password = ''
def driver = 'oracle.jdbc.driver.OracleDriver'

 

// Register the MySQL JDBC driver – required for Groovy to send requests to the database.
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(driver)

// Connect to the SQL instance.
def sql = Sql.newInstance(url, user, password,driver)

// Use the SQL instance.
sql.execute('')


// Close the SQL instance.
sql.close();

 

 

Exception :

Mon Jun 01 17:57:18 CDT 2020:ERROR:java.lang.ClassNotFoundException: oracle.jdbc.pool.OracleDataSource
java.lang.ClassNotFoundException: oracle.jdbc.pool.OracleDataSource
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at groovy.sql.Sql.loadDriver(Sql.java:705)
at groovy.sql.Sql.newInstance(Sql.java:445)
at groovy.sql.Sql$newInstance.call(Unknown Source)
at Script4.run(Script4.groovy:21)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

 

Can anyone help me here ?

 

Setup :

I have added the JDBC files in to C:\Program Files\SmartBear\SoapUI-5.4.0\lib and C:\ProgramFiles\SmartBear\SoapUI-5.4.0\bin\ext. Still getting the same error. Did restart after the above setup also

  • The Connection string was good .. My issue was it is not loading the jar from external.. The below code finally helped me directly loading the files.. Now my code is working.. Thanks a lot of all of you guys for helping me here....

     

     

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def classpathHacker = new com.eviware.soapui.support.ClasspathHacker ()

    log.info "utils=" + groovyUtils
    path = ".../SoapUI-5.4.0/bin/ext"
    myfile = new java.io.File(path + "/ojdbc8.jar")
    mystring = "file://" + path + "/ojdbc8.jar"
    log.info "myfile=" + myfile

    classpathHacker.addFile( myfile )
    com.eviware.soapui.support.ClasspathHacker.addFile( myfile )
    com.eviware.soapui.support.ClasspathHacker.addURL( new URL(mystring) )

     

    import groovy.sql.Sql
    import groovy.sql.*
    import java.sql.SQLException
    import oracle.jdbc.driver.*
    //import com.eviware.soapui.support.GroovyUtils.*

    // Set up database connection properties.
    def url = 'jdbc:oracle:thin:'
    def user = ''
    def password = ''
    def driver = "oracle.jdbc.driver.OracleDriver"

    com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("net.sourceforge.jtds.jdbc.Driver")
    sql = Sql.newInstance(url, user, password,driver)
    def query = ""
    def res = sql.execute(query)

7 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Restart the tool after placing the driver file under SoapUi installation/bib/ext directory if not already done.
    • Dipin's avatar
      Dipin
      New Contributor

      Tried that and it is not working. Getting the same error

      • nmrao's avatar
        nmrao
        Champion Level 3
        Please remove it from lib directory and restart.