SoapUI JDBC connection with Apache Cassandra

前端 未结 4 777
长发绾君心
长发绾君心 2021-01-16 03:43

Does anyone know how to connect to cassandra using JDBC connection string in SoapUI.

I have tried from my side, but not able to connect. Based on the research I came

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-16 03:54

    This was fun, I have never worked with Cassandra before so it took me sometime to figure this one out and I think i have.

    To use Cassandra you need multiple jar files, below is a screenshot of the ones i used. enter image description here

    I used the cassandra-cli to find out the correct port number, in my case it was 9160.

    The correct connection string is jdbc:cassandra://localhost:9160/soapuikeyspace and the correct driver is org.apache.cassandra.cql.jdbc.CassandraDriver. When i tried to access Cassandra from teh JDBC step i was able to succesfully connect to Cassandra but when i tried to run a select query i got

    Error getting response

    and the following error trace in the soapUI logs

    Sat Apr 05 17:33:09 ADT 2014:ERROR:java.sql.SQLFeatureNotSupportedException
       java.sql.SQLFeatureNotSupportedException
        at org.apache.cassandra.cql.jdbc.CassandraResultSet$CResultSetMetaData.getTableName(CassandraResultSet.java:1307)
        at com.eviware.soapui.support.xml.XmlUtils.addResultSetXmlPart(XmlUtils.java:1712)
        at com.eviware.soapui.support.xml.XmlUtils.createJdbcXmlResult(XmlUtils.java:1651)
        at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcResponse.(JdbcResponse.java:38)
        at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.createResponse(JdbcSubmit.java:334)
        at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.runQuery(JdbcSubmit.java:199)
        at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.run(JdbcSubmit.java:161)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    

    So that approach was a bust.

    It wasn't a complete failure because I was able to access Cassandra and run queries against it. I used the below code to do that.

    import java.sql.DriverManager;
    import java.sql.SQLFeatureNotSupportedException;
    import java.sql.Statement;
    import javax.sql.DataSource;
    import org.apache.cassandra.cql.jdbc.*;
    
    com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("org.apache.cassandra.cql.jdbc.CassandraDriver");
    def con = DriverManager.getConnection("jdbc:cassandra://localhost:9160/soapuikeyspace"); //keyspace has to be in lowercase
    
     def stmt = con.createStatement();
    
    //add data
    def qry = "insert into users (user_id, lname, fname) values (1747,'Abhishek','Asthana');"
    def rs = stmt.executeUpdate(qry)
    

    The most important thing to remember when using this code is to write the keyspace name in lowercase.

    For anyone interested, i wrote a blog about all this.

提交回复
热议问题