Ask Ben: Processing A Query In Java
Posted July 19, 2006 at 2:31 PM by Ben Nadel
How do you send and process a coldfusion query to a java object created by cfobject (not through cfx)?
I have to admit, as my Car Talk friends would say, this one "Stumped the Chump". I am not a Java expert. From what I have read though, underlying the ColdFusion query object is the Java class:
This implements the Java interfaces for:
javax.sql.RowSet and coldfusion.wddx.RecordSet
When you send ColdFusion objects to Java, ColdFusion generally does a type-cast automatically to the appropriate Java type. I am not sure how to test this here, but you might be able to pass the Query object directly to Java. If not, you can explicitly convert the Query object to the Java QueryTable object:
- <cfset jQueryTable = CreateObject(
- ).Init( qColdFusionQuery )
... or as CFObject ...
- <!--- Initialize the object. --->
- <cfset jQueryTable.Init( qColdFusionQuery ) />
This creates an instance of the Java QueryTable and passes in your ColdFusion query (qColdFusionQuery) as a the constructor argument. Then, once you get this object into your Java arena, you can use the built in methods to manipulate it. I got this list off of the page http://www.activsoftware.com/mx/undocumentation/query.cfm originally posted on Pete Freitag's site:
sort(int columnID, boolean ascending)
... many more functions here ...
As far as passing this into a function or returning it from a function, you just have to make sure that object type is defined as "coldfusion.sql.QueryTable".
As someone commented on Pete's site (linked above), to get back to a regular ColdFusion query object, you can do:
- <cfset qActualColdFusionQuery = jQueryTable.FirstTable() />
When I first started looking into this question, I went about it with the idea of building up a ResultSet from scratch. I couldn't find any information on that at all. Then I thought maybe casting XML to ResultSet somehow? No go on that either. But since the QueryTable class implements the interfaces for RowSet, you should be able to do just about everything you want to do.
NOTE: I learned about this FOR the answer and it may contain misinformation.
What Other People Are Searching For
[ local search ]
coldfusion passing a query object to a java class
- Wanted: Full-Time ColdFusion Developer at Intoria Internet Architects
- Cold Fusion Senior Developer at Edge Information Management
- Back-End Web Developer-Information Technologist at Michigan State University
- ColdFusion Developer at Nonfat Media
- Mid-to-Senior Level Web Application Developer at SiteVision, Inc.