Forum Discussion

gargantouas's avatar
gargantouas
Occasional Contributor
7 years ago

Cassandra Connection with Groovy Script In SoapUI

Dear Community,

   thanks for the time. I am trying to access a remote Cassandra DB in order to complete my assertions. I see that the Server is running:

  • Cassandra V 3.0.8.1293
  • Driver Type: Cassandra CQL
  • Datastax Java Driver for Apache Cassandra - Core [3.0.5]

 

So, I am trying with the following code to access the DB

import com.datastax.driver.core.*

Cluster cluster = null;
try {
    cluster = Cluster.builder().addContactPoint("x.x.x.x").withCredentials("xxxxxxx", "xxxxxx").withPort(9042).build()
    
    Session session = cluster.connect();                         

   ResultSet rs = session.execute("select * from TABLE");   
   Row row = rs.one();
} finally {
    if (cluster != null) cluster.close();  
}

when I use the cassandra-driver-core-2.0.1.jar I am getting the error :

ERROR:com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /x.x.x.x(null))

Read the documentation and a lot of posts here and on other blogs and I saw that there may be an incompatibility with the driver version so I tried to upgrade the driver to many versions (cassandra-driver-core-2.5,cassandra-driver-core-3,cassandra-driver-core-3.2), but on that I am getting the following:

 

ERROR:java.lang.ExceptionInInitializerError

Have also tried to connect using JDBC, but to no avail. using the configuration proposed at this thread

https://community.smartbear.com/t5/SoapUI-NG/Apache-Cassandra-CQL-jdbc-connection/td-p/40050

 

Actually I am running out of ideas. Can anyone propose or point to some direction on how to actually achieve this, either by pointing me to some tutorial or any idea.

Thank you very much

4 Replies

    • gargantouas's avatar
      gargantouas
      Occasional Contributor

      No, I have already tried that one, actually I think I have tried almost all the suggested solutions that do not contain rebuilding the driver.... 

    • pedro's avatar
      pedro
      Occasional Contributor

      I have tried to use the code provided but I am having the following error message while trying to stablish the connection to cassandra: 

       

      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://IP_ADDRESS:9042/activation"); //keyspace has to be in lowercase

       

      def stmt = con.createStatement();

      //add data
      def qry = "SELECT * fROM activation WHERE activation_id = '001010126' and activation_N_id ='01';"
      def rs = stmt.executeUpdate(qry)

       

      ERRROR MESSAGE

      java.sql.SQLExeption: Incorrect URL: jdbc:cassandra...

      (Image Attached)

       

      I got information from my DevTeam that this is a cassandra database uses a NATIVE PORT : 9042.

       

      Does anybody have any more information about what might be the reason I am getting the error above?

       

      Thanks for your help!

       

      • gargantouas's avatar
        gargantouas
        Occasional Contributor

        This is a connection using JDBC and not the core datastax drivers. Please open a new thread. pedro