問題描述
以下在 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 查詢?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!