如何在 Railo 中将 Java 结果集转换为 ColdFusion 查询?

时间:2022-11-20
本文介绍了如何在 Railo 中将 Java 结果集转换为 ColdFusion 查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

以下在 CFMX 7 和 CF8 中运行良好,我也假设 CF9:

The following works fine in CFMX 7 and CF8, and I'd assume CF9 as well:

<!--- 'conn' is a JDBC connection --->
<cfset stat = conn.createStatement() />
<cfset rs = stat.executeQuery(trim(arguments.sql)) />

<!--- convert this Java resultset to a CF query recordset --->
<cfset queryTable = CreateObject("java", "coldfusion.sql.QueryTable")>
<cfset queryTable.init(rs) >
<cfset query = queryTable.FirstTable() />

这将使用 JDBC 驱动程序创建一条语句,对其执行查询,将其放入 java 结果集中,然后实例化 Coldfusion.sql.QueryTable,传递 Java resulset 对象,然后调用 queryTable.FirstTable(),它返回一个实际的冷融合结果集(用于 cfloop 等).

This creates a statement using a JDBC driver, executes a query against it, putting it into a java resultset, and then coldfusion.sql.QueryTable is instantiated, passed the Java resulset object, and then queryTable.FirstTable() is called, which returns an actual coldfusion resultset (for cfloop and the like).

问题在于 Railo 的实现方式有所不同.在 Railo 中运行此代码会返回以下错误:No matching Constructor for coldfusion.sql.QueryTable(org.sqlite.RS) found.

The problem comes with a difference in Railo's implementation. Running this code in Railo returns the following error: No matching Constructor for coldfusion.sql.QueryTable(org.sqlite.RS) found.

我已经转储了 Railo java 对象,但在方法中没有看到 init().我错过了一些简单的东西吗?我也很想在 Railo 中使用它.

I've dumped the Railo java object, and don't see init() among the methods. Am I missing something simple? I'd love to get this working in Railo as well.

请注意:我正在与 SQLite 数据库进行无 DSN 连接.我了解如何设置 CF 数据源.在这一点上,我唯一的问题是将 Java 结果集转换为 Railo 查询.

Please note: I am doing a DSN-less connection to a SQLite db. I understand how to set up a CF datasource. My only hiccup at this point is doing the translation from a Java result set to a Railo query.

推荐答案

查看 Railo 源代码,我发现 railo.runtime.type.QueryImpl 可能适合您的需求.它实现了 railo.runtime.type.Query 并在其构造函数中接受一个 ResultSet,但它似乎没有实现 QueryTable.

Looking at the Railo source code, I see that railo.runtime.type.QueryImpl might fit your needs. It implements railo.runtime.type.Query and accepts a ResultSet in its constructor, but it does not seem to implement QueryTable.

如果这是正确的类,您需要传入一个 ResultSet 和一个用于查询名称的字符串,因为它没有只接受 ResultSet 的构造函数.

If that's the right class, you'll want to pass in a ResultSet and a string for the query name, as it doesn't have a constructor that only takes a ResultSet.

这篇关于如何在 Railo 中将 Java 结果集转换为 ColdFusion 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在 ColdFusion 中,有没有办法确定代码在哪个服务器上运行? 下一篇:在 ColdFusion 中以编程方式验证邮件服务器连接

相关文章

最新文章