3 Replies Latest reply on Aug 3, 2009 3:05 PM by -==cfSearching==-

    Create a CF Query Result Set in Java


      I'd like to programatically build a ColdFusion query resultset inside of a Java class and return it to the calling application.  See the Java psudocode below to see what I'm talking about:


      public class MyClass {

           public coldfusion.sql.QueryTable getQuery() {

                // Create a query table object

                QueryTable myTable = ..?


                // Loop through some set of instance data for my class

                for(int c = 0; c < this.myWigets.length; c++) {

                     int row = c+1;

                     myTable.setField(row, nameCol, this.myWigets[c].name);

                     myTable.setField(row, colorCol, this.myWigets[c].color);



                return myTable;




      I've had stuff like this partially working in the past but had issues with things like query of queries and such probably due to the hacks used to create the QueryTable object.  I'm mainly just checking in to see if there has been any progress made in this area.  To me this seems like such an obvious thing for a Java developer working within CF to want to do.  I'm surprised Adobe doesn't have an officially supported API for doing this sort of thing (or maybe I'm just too dumb to find it.)    A few other notes... I'm not using CFX, and I'm not starting with a java.sql.ResultSet otherwise I would use the QueryTable(java.sql.ResultSet) constructor.  I need to build this thing from scratch programatically.


      Thanks for your time.  I hope this question makes sense to someone out there.


      - Mike

        • 1. Re: Create a CF Query Result Set in Java
          Dan Bracuk Level 5

          I think it would be a lot easier to write a webservice with cfml and call it with java.  By the way, this calling application that needs a cfquery object, is it cold fusion?

          • 2. Re: Create a CF Query Result Set in Java
            MikeP Level 1

            I appologize.  I wasn't very clear with my original question.


            I'm creating an instance of my Java class from within CF using createObject("java", "com.example.MyClass").  So based on the sample code in my original post on the CF side I'd like to do something like this:


                 myObj = createObject("java", "com.example.MyClass");




                 myCFQuery = myObj.getQuery();  // Return a CF query from my java class



            ... then do stuff like ...


            <cfquery name="mySortedQuery" dbtype="query">

                 select     *

                 from       myCFQuery

                 order      by color



            I appriciate your suggestions so far.  I have other solutions working already but they are not ideal.  I was just hoping someone had a clean and as-hack-free-as-possible way of creating a ColdFusion query result set in Java and passing it back to CF.


            Thanks again,


            • 3. Re: Create a CF Query Result Set in Java
              -==cfSearching==- Level 4

              I do not think there is a documented api, other than the one for cfx tags.  Though I would love to see one myself ..