Using Apache Cassandra in Coldfusion

I am trying to use Apache Cassandra in a project that I am coding using Coldfusion. Since Coldfusion does not have a driver for Apache Cassandra and vice versa, I am trying to use Cassandra Java drivers.

I am pretty new to Java, so please bear with me.

I managed to copy the necessary .jar files to / opt / railo / lib / (I use Railo) and also managed to connect to Cassandra using Coldfusion using the code below. I need help, this is a loop of results returned by Cassandra when executing a query. I have included my very simple code below:

<cfset MyClusterInit = CreateObject("java", "com.datastax.driver.core.Cluster")>
<cfset MyCluster = MyClusterInit.builder().addContactPoint("127.0.0.1").build()>
<cfset MySession = MyCluster.connect("mytest")>
<cfset GetCustomer = MySession.execute("SELECT * FROM customer")>
<cfdump var="#GetCustomer#">

How do I get through the returned results? Cfdump returns the Java method ArrayBackedResultSet $ ​​SinglePage. This is not something that I can iterate through with Coldfusion.

From the “Getting Started With Cassandra and Java” message, I see the code as shown below:

ResultSet results = session.execute("SELECT * FROM users WHERE lastname='Jones'");
for (Row row : results) {
System.out.format("%s %d\n", row.getString("firstname"), row.getInt("age"));
}

How to reproduce above in Coldfusion?

Thanks so much for your time to help.

+4
source share
1 answer

As mentioned by Leigh and Mark A Kruger, using the JDBC driver was a smarter way to connect to Cassandra in Coldfusion / Railo. Just follow the steps below:

  • Download the JDBC driver at https://code.google.com/a/apache-extras.org/p/cassandra-jdbc/ . It works with the latest version of Cassandra (at the time of writing).

  • Be sure to download the Cassandra JDBC dependencies

  • Copy jar files to Coldfusion library directory

  • Coldfusion/Railo

  • ""

  • " org.apache.cassandra.cql.jdbc.CassandraDriver"

  • " jdbc: cassandra://host1 - host2 - host3: 9160/keyspace1? primarydc = DC1 & backupdc = DC2 & constency = QUORUM"

  • ! Cassandra,

. Java- , JDBC- , Java-. 3 , 50 Java, JDBC 5 .

Leigh Mark A Kruger !

+6

All Articles