user6900728
user6900728

Reputation:

Connecting to MariaDB using Soapui

I am trying to connect to the database using SOAPUI to check if the values were updated properly. But I am having trouble doing it. Also, due to the security reasons I will need to login through SSH and we are currently using maria db(not sure which driver i use matters here)

Here is what I tried:

import groovy.sql.Sql
def driver="oracle.jdbc.driver.OracleDriver"
def username='wonder'
def password='welcome9'
def sql = Sql.newInstance(path,username,password,driver)
def state="select * from Company"
sql.execute(state)

Also, Can i do this in the script assertion and where should i paste my driver?

Upvotes: 0

Views: 522

Answers (1)

Rao
Rao

Reputation: 21379

Here are the instructions to do so:

  • download the driver file and its dependency libraries form here or pre-build jar file from here or from maven repository
<dependency>
    <groupId>org.mariadb.jdbc</groupId>
    <artifactId>mariadb-java-client</artifactId>
    <version>xxx</version>
</dependency>
  • copy the download jar files under SOAPUI_HOME/bin/ext directory
  • restart soapui tool if already running
  • in the Groovy Script where you write the code to connect to db, first you need to register the driver using below statement:

    com.eviware.soapui.support.GroovyUtils.registerJdbcDriver( "org.mariadb.jdbc.Driver" )

So, the script may look like:

//Below is just a sample
//Change values as needed in below connection
def driver = 'org.mariadb.jdbc.Driver'
def connectionString = 'jdbc:mariadb://localhost:3306/db'
def user = 'your_user'
def password = 'secret'
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(driver)
def sql = Sql.newInstance(connectionString, user, password, driver)
def query = 'select * from company'
sql.execute(query)

For more details on mariadb, please check the documentation

Hope this is helpful.

Upvotes: 2

Related Questions