在ColdFusion中使用Apache Cassandra [英] Using Apache Cassandra In Coldfusion

查看:145
本文介绍了在ColdFusion中使用Apache Cassandra的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我使用Coldfusion编写的项目中使用Apache Cassandra。由于Coldfusion没有Apache Cassandra的驱动程序,反之亦然,我试图使用Cassandra的Java驱动程序。

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.

我几乎是一个Java新手,所以请

I'm pretty much a Java newbie so please bear with me.

我已经设法将必要的.jar文件复制到/ opt / railo / lib /(我使用Railo)到Cassandra使用Coldfusion使用下面的代码。我需要帮助是循环通过Cassandra返回的结果,当我运行查询。我已经在下面包含了我的非常简单的代码:

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#">

如何循环返回结果? cfdump返回Java方法ArrayBackedResultSet $ SinglePage。这不是我可以循环使用Coldfusion。

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.

从Cassandra和Java入门帖子,我看到代码如下:

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"));
}

如何在Coldfusion中复制上述内容?

How do I replicate the above in Coldfusion?

非常感谢您花时间帮助。

Many thanks for taking your time to help.

推荐答案

正如Leigh和Mark A Kruger上面,使用JDBC驱动程序是在Coldfusion / Railo连接到Cassandra的更聪明的方式。只需按照以下说明操作:

As pointed out by Leigh and Mark A Kruger above, using the JDBC driver was the smarter way to connect to Cassandra in Coldfusion/Railo. Just follow the instructions below:


  1. 下载JDBC驱动程序 https://code.google.com/a/apache-extras.org/p/cassandra-jdbc/

请务必同时下载Cassandra JDBC依赖项

Make sure to also download the Cassandra JDBC dependencies

将jar文件复制到Coldfusion lib目录

Copy the jar files to your Coldfusion lib directory

重新启动Coldfusion / Railo

Restart Coldfusion/Railo

创建数据源类型其他

对于驱动类,输入 org.apache.cassandra.cql .jdbc.CassandraDriver

连接字符串应为 jdbc:cassandra:// host1 - host2 - host3: 9160 / keyspace1?primarydc = DC1& backupdc = DC2& consistency = QUORUM

不仅如此。我设法使Java驱动程序直接工作,JDBC驱动程序的性能比直接调用Java驱动程序好得多。我的测试只是一个非常简单的表,有3条记录,花了50ms直接使用Java连接,而使用JDBC驱动程序花费不到5ms。

Not only that. I managed to get the Java driver working directly and the performance of the JDBC driver was much better than calling the Java driver directly. My test was just a very simple table with 3 records and it took 50ms to connect directly using Java while using the JDBC driver took less than 5ms.

感谢Leigh和Mark克鲁格的提示!

Thanks to Leigh and Mark A Kruger for the tip!

这篇关于在ColdFusion中使用Apache Cassandra的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆