free seo tool

soapUI JDBC Connection configuration settings using groovy Script

In soapUI Pro, there is an option to configure a JDBC database connection and it can be accessed in many places like DataSource test step, JDBC Request step, DataSink step etc. But in some cases, we might need to get the same JDBC connection object and connection details in groovy script as well. In this post we will take a quick look on how can we get the JDBC connection properties in groovy script editor (Script test step).
  • First of all, double click on your project on the left side pane of soapUI.
  • Now, navigate to the tab "JDBC Connections" on the right side pane.
  • Click on the plus sign and provide the necessary details and configure the database connection.
  • Name the connection as "JDBCTest1" (we will be referring this JDBC connection later on the groovy script.)
  • Test the JDBC connection before closing the dialog box.
Now use the below code to create a connection object and get the properties to use it in groovy script.import groovy.sql.Sql;
// Below line will create an object of the already created JDBC connection.
def ConObj = context.testCase.testSuite.project.databaseConnectionContainer.getDatabaseConnectionByName('JDBCTest1');
//Below line is using the connection String from already created JDBC connection.
def Con = Sql.newInstance(ConObj.getConnectionString());
def res = Con.rows("select *from tablename;");
Con.close();
5 comments:
  • Linkesh Kanna Velu says:
    April 30, 2015

    Thanks. This is what I am looking for.

  • Anonymous says:
    May 12, 2015

    How can we use groovy scripting with DataSource and DataConnection

  • Unknown says:
    January 31, 2017

    Nice job!

    This helped me into the right path but i am not there yet. I am looking for a way of selecting in one place one of the preconfigured database connections and to set the same configuration to all JDBC requests in my different test suites.

    Hopefully you can help me with this.

    Thanks in advance!

  • Anonymous says:
    July 27, 2017

    which version of soapui does this supports

  • Anonymous says:
    July 27, 2017

    i was unable to find the JDBC connection step when i double clicked on my project

Post a Comment

This is a new website mainly for SOA Testers using soapUI. Let me know your thoughts/ suggestions.