I'm trying to use Apache Cassandra on a project I'm coding using Coldfusion. Since Coldfusion doesn't have a driver for Apache Cassandra and vice versa, I'm attempting to use Cassandra's Java drivers.
I'm pretty much a Java newbie so please bear with me.
I've managed to copy the necessary .jar files to /opt/railo/lib/ (I'm using Railo) and also managed to connect to Cassandra using Coldfusion using the code below. What I need help with is looping through the results returned by Cassandra when I run a query. I've 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 loop through the results returned? The cfdump returns the Java method ArrayBackedResultSet$SinglePage. It's not something that I can loop over using Coldfusion.
From the "Getting Started With Cassandra and Java" post, I see the code as 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 do I replicate the above in Coldfusion?
Many thanks for taking your time to help.