Forum Discussion

Adrian's avatar
Adrian
New Contributor
14 years ago

JDBC Request with external drivers

Hi there,

I am a soapUI Newbie and got the Trial Version of Version 3.5 Pro. After almost a full day of googeling, I can't find the solution for my problem.
I want to connect some parts of my project via JDBC request with a db2/AS-400 database. Therefore I copied the driver "DB2 for AS/400 (JTOpen)" in the soapUI/bin/ext-directory and got following message in the log after restarting soapUI: [...] "INFO: Added [...] /bin/ext/jt400.jar to classpath".
Now I inserted a JDBC Request. How can I use my imported file? Moreover I cannot find my driver in the Preferences -> Jdbc Driver Properties Section. How can I add my driver manually so that it can be used in my JDBC Request?
Of course I can manually add the driver but what do I have to put in the driver column (like "IBMDB2/COM.ibm.db2.jdbc.app.DB2Driver") or is their no deeper sense in this declaration?
If I add the driver manually I get different exceptions while configuring the JDBC Request:
- "Failed to load JDBC driver jt400"
- Can't get the Connection for specified properties; java.lang.Exception: Failed to init connection for drvr [jt400], connectionString [jdbc:as400://yyy.yyy.yyy.yyy?user=YYYYYYY&password=PASS_VALUE]

Thanks for your help and kind regards,
Adrian
  • Adrian's avatar
    Adrian
    New Contributor
    Thanks for the quick answer!
    That's what I already did - I already got the message in the log file that my jar file is added to the classpath. The problem is how can I use this file with a JDBC Request, see my description above.

    Now I inserted a JDBC Request. How can I use my imported file? Moreover I cannot find my driver in the Preferences -> Jdbc Driver Properties Section. How can I add my driver manually so that it can be used in my JDBC Request?
    Of course I can manually add the driver but what do I have to put in the driver column (like "IBMDB2/COM.ibm.db2.jdbc.app.DB2Driver") or is their no deeper sense in this declaration?
    If I add the driver manually I get different exceptions while configuring the JDBC Request:
    - "Failed to load JDBC driver jt400"
    - Can't get the Connection for specified properties; java.lang.Exception: Failed to init connection for drvr [jt400], connectionString [jdbc:as400://yyy.yyy.yyy.yyy?user=YYYYYYY&password=PASS_VALUE]
  • Ok this is how im doing. Hope it will help you:
    On the top testSuite setup secript (like @beforeClass for Junit)before anything :


    import groovy.sql.Sql;
    import org.apache.commons.io.FileUtils;


    //get the jdbc url define as a project property
    //useful to change it dynamically for a specific environnement manually or dynamically via the maven Plugin with a specifi
    //profil

    def datasource=context.expand('${#Project#datasource.url}');


    //!!!!!!!!!WARNING!!! Mandatory to use since >=3.6.2 the 2 following lines
    //to register the jdbc
    //def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
    //groovyUtils.registerJdbcDriver("org.postgresql.Driver");

    if( datasource != null ) {
    log.info "Definition of the datasource =:"+datasource;
    }
    def sql;

    sql = Sql.newInstance(datasource, "postgres","postgres", "org.postgresql.Driver");



    //we get the relative root of the soapuiProject
    def projectroot = context.expand('${projectDir}');


    //the file si read according to the relative root of the sopaui project
    File file = new File(projectroot+"//soapui.sql");
    def sqlFileContent= FileUtils.readFileToString(file);

    //execute the sql file
    sql.execute(sqlFileContent);