Let me say first off that I'm not very experienced with cfc's.
Code below is a cfc to query a sage line 100 accounting db from cf8.1
This works, a normal query via a regular datasource type ODBC socket
doesn't (though it does in CF5).
My question: I understand that when using JDBC it is important to make
sure you close each resultset, statement and connection. You'll notice
I'm outputting a JDBC recordset from the method sQuery in the var
jdbcRecordset. I'd like to do this so I can do various other things
with it in the next stage (ie actually call sQuery from other methods in
the cfc) BUT - by passing it like this, is it actually closing the
connection, or am I going to end up gobbling up memory because it's
passed it by reference and actually kept it open?
Thanks
Richard
the script:
=========================================
<cfcomponent
displayname="sageQuery"
output="false"
hint="Handles the reading and output of data from sage.">
<cffunction name="Init"
access="public"
returntype="sageQuery"
output="false"
hint="Returns an initialized sageQuery instance.">
<!--- Return This reference. --->
<cfreturn THIS />
</cffunction>
<CFFUNCTION name="sQuery"
hint="Returns a java recordset from the query">
<CFARGUMENT name="datasource"
required="true"
hint="ODBC datasource name of the sage db to be
queried">
<CFARGUMENT name="sql"
required="true"
hint="SQL to run in the sage query">
<CFSET var uid = "xxx">
<CFSET var pwd = "yyy">
<CFSET var jdbcRecordset = "">
<cftry>
<!--- This cfobject creates a java object of type Class. Leave this
statement as it is. --->
<cfobject type="JAVA" action="Create" name="Class"
class="java.lang.Class">
<!--- The java class name for your driver is the argument for
Class.forName --->
<cfset Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")>
<!--- This cfobject creates a DriverManager java object which
provides your connection --->
<cfobject type="JAVA" action="Create" name="DriverManager"
class="java.sql.DriverManager">
<!--- The getConnection method takes the JDBC URL for your
driver as its arguement --->
<!--- jdbc:odbc:[datasource];[UID=username];
[PWD=password];[args] --->
<cfset con =
DriverManager.getConnection("jdbc:odbc:#ARGUMENTS.datasource#;UID=#uid#;
PWD=#pwd#;")>
<!--- the createStatement method takes no arguments --->
<cfset st = con.createStatement()>
<!--- Your query statement is the argument for executeQuery --->
<!--- <cfset rs = st.executeQuery("SELECT ACCOUNT_NAME,
ACCOUNT_NUMBER FROM SALES_LEDGER")> --->
<cfset rs = st.executeQuery("#sql#")>
<!--- <cfset ourQuery = resultSetToQuery(rs)> --->
<cfset jdbcRecordset = rs>
<!--- When using JDBC it is important to make sure you close
each resultset, statement and connection. This is done in the next
block of code. --->
<cfset rs.close()>
<cfset st.close()>
<cfset con.close()>
<cfcatch>
<cfdump label="Error 1" var="#cfcatch#"><cfabort>
</cfcatch>
</cftry>
<CFRETURN jdbcRecordset>
</CFFUNCTION>
</cfcomponent>
=========================================
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:304458
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4