cancel
Showing results for 
Search instead for 
Did you mean: 

Data Base Connection using Groovy Script in SOAP UI

SOLVED
Highlighted
New Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
New Contributor

Re: SOAP : Groovy : java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

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)

View solution in original post

7 REPLIES 7
Highlighted
Community Hero

Re: Data Base Connection using Groovy Script in SOAP UI

Restart the tool after placing the driver file under SoapUi installation/bib/ext directory if not already done.


Regards,
Rao.
Highlighted
New Contributor

Re: Data Base Connection using Groovy Script in SOAP UI

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

Highlighted
Community Hero

Re: Data Base Connection using Groovy Script in SOAP UI

Please remove it from lib directory and restart.


Regards,
Rao.
Highlighted
Community Hero

Re: Data Base Connection using Groovy Script in SOAP UI

Hi @Dipin,

Can you confirm youre trying to connect to an Oracle database rather than MySQL database?

Reason i ask is that you make a couple of references to MySQL as well as Oracle in your post.

For example, your post includes the following lines

def url = '' /* IMPORTANT: must start with jdbc:mysql:// */
def user = ''
def password = ''
def driver = 'oracle.jdbc.driver.OracleDriver'

So you appear to be trying to use the Oracle driver, but the comment when you define the url variable (line starting 'def url') indicates the connection URL string should begin 'jdbc:mysql:' rather than what i'd expect it to begin with 'jdbc:oracle:' if you are connecting to an Oracle database. Also make sure you have the parameters in the string setup correctly for Oracle rather than MySQL cos connection URLs differ between database vendors.

Cheers,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
New Contributor

SOAP : Groovy : java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

yeah i am trying to connect to oracle, provided the ConnectionURL below.
 
url = 'jdbc:oracle:thin:@
 
Highlighted
Community Hero

Re: SOAP : Groovy : java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

Hey @Dipin,

Have a look at the following link....this describes a solution for connecting to an oracle database via groovy. (https://community.atlassian.com/t5/Adaptavist-questions/Groovy-connect-to-Oracle-db/qaq-p/988693)

Also, regarding your connection string. You didnt include the port number (default is 1521 in oracle) nor a Service Name or SID in your last post. Your last post just had the following:

jdbc:oracle:thin:@ldap

But youre gonna need both port and Service Name/SID in the connectiom string i wouldve thought.

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
New Contributor

Re: SOAP : Groovy : java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

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)

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors