Forum Discussion

kamleshwaghela0's avatar
11 years ago

Apache Cassandra CQL - jdbc connection

Hi,

Could you please advise, whether SoapUI support Apache Cassandra jdbc connection strings.

If it does then could you please confirm whether I have used correct information.

Driver: org.apache.cassandra.cql.jdbc.CassandraDriver
Connection String: jdbc:cassandra://localhost:8080/test2

Just to let you know I have also added cassandra jdbc.jar file in the soapui ext folder.

Appreciate your help.

Best Regards,
Kam
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    Hi Kam,

    I am not familiar with your particular DB set up but if it's supported in Java than typically it is supported in SoapUI (Groovy) as well. Just treat it like it's Java and import the driver and then build the connection.
  • GiscardN's avatar
    GiscardN
    Frequent Contributor
    Hi,

    I have seen that connection string format but you should make sure you have all you need in it or whether some credentials are also necessary. I suggest you create a connection string template in SoapUI Preferences (from File menu), on the JDBC Drivers Properties tab for your database. Add an entry for your database: Ex: jdbc:cassandra://<HOST:127.0.0.1>:<PORT:50000>/<DB>
    That way you can configure the JDBC TestStep using the Configure button when you select your database.
    Having the driver placed in the \bin\ext folder, that setup should work.

    Regards,

    Giscard
    SmartBear Support
    • raghuraghavan's avatar
      raghuraghavan
      Occasional Visitor

      I trying to connect to Cassandra database, I have all the dependencies in the bin/ext folder for ready api. When connecting to the cassandra, I getting the following error " Can't get the Connection for specified properties; java.sql.SQLNonTransientConnectionException: Keyspace names must be composed of alphanumerics and underscores (parsed: 'cassandra@localhost:9042/demo23_123') " even though i have keyspace name as suggested.

       

      I did try to connect with groovy script as well. Did get the same error

       

      here is the code for grovvy script

      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://cassandra/cassandra@localhost:9042/demo23_123"); //keyspace has to be in lowercase

       def stmt = con.createStatement();

      //add data
      def qry = "select * from patient"
      def rs = stmt.executeUpdate(qry);

       

      Request to suggest to continue this R&D activity.

       

      Thanks

      Raghu Raghavan

       

       

      • JahnaviAkkineni's avatar
        JahnaviAkkineni
        Occasional Contributor

        Hi Raghu,

        Were you able to connect to cassandra using SOAP UI?

  • abhishek813's avatar
    abhishek813
    Frequent Contributor
    I hope its not too late but i was able to access Cassandra from soapUIs groovy test step.

    The below short piece of code does the job but to be able to use this code you should have certain jars (see attached image) in the ext folder.

    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)




    For anyone interested, i have written a blog about this too at http://abhishekasthana.com/accessing-cassendra-soapui/.
    • JahnaviAkkineni's avatar
      JahnaviAkkineni
      Occasional Contributor

      I tried using the script posted and I am seeing the same error as well. No suitable driver for jdbc:cassandra

  • shuiyiting's avatar
    shuiyiting
    New Contributor

    jdbc connection by thrift are disable in cassandra, to resolve that i tried connect by dse-driver, here are my steps:

     

    1. copy these jars into soapui bin/ext:

      dse-java-driver-core-1.4.0

      dse-java-driver-mapping-1.4.0

      metrics-core-3.0.2

      netty-all-4.1.6.Final

    2. update guava jar in lib:

      guava-18.0

    3. launch soapui and create groovy script:

     

    import com.datastax.driver.core.*;
    
    Cluster cluster = null;
    
    cluster = new Cluster.Builder().addContactPoints("127.0.0.1").withPort(9042).build();
        
    Session session = cluster.connect();                         
    PreparedStatement statement = session.prepare("select * from keyspace.exemple_table");
    
    ResultSet rs = session.execute(statement.bind());
    Row row = rs.one();