Just to slightly modify what I've already done, is this what you're refereing to Barney?
The only downside is that since the password is encrypted in the structure, the password would still have to be supplied.
<cffunction name="dump">
<cfdump var="#Arguments[1]#">
</cffunction>
<cfscript>
namedDatasource = "db";
password = "password";
ServiceFactory = CreateObject("java", "coldfusion.server.ServiceFactory");
datasources = ServiceFactory.getDataSourceService().getDatasources();
if(StructKeyExists(datasources, namedDatasource))
dataSourceStruct = StructFind(datasources, namedDatasource);
try {
Class = createObject("java","java.lang.Class").forName(dataSourceStruct.class);
DriverManager = createObject("java", " java.sql.DriverManager");
conn = DriverManager.getConnection(dataSourceStruct.url, dataSourceStruct.username, password);
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from program");
newQuery = CreateObject("java", "coldfusion.sql.QueryTable").init(rs);
dump(newQuery);
stmt.Close();
conn.Close(); // clean up.
}
catch (any e) {
WriteOutput("Error!<br />");
dump(e.message);
if(IsDefined("stmt")) stmt.Close();
if(IsDefined("conn")) conn.Close();
}
</cfscript>
<cfdump var="#Arguments[1]#">
</cffunction>
<cfscript>
namedDatasource = "db";
password = "password";
ServiceFactory = CreateObject("java", "coldfusion.server.ServiceFactory");
datasources = ServiceFactory.getDataSourceService().getDatasources();
if(StructKeyExists(datasources, namedDatasource))
dataSourceStruct = StructFind(datasources, namedDatasource);
try {
Class = createObject("java","java.lang.Class").forName(dataSourceStruct.class);
DriverManager = createObject("java", " java.sql.DriverManager");
conn = DriverManager.getConnection(dataSourceStruct.url, dataSourceStruct.username, password);
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from program");
newQuery = CreateObject("java", "coldfusion.sql.QueryTable").init(rs);
dump(newQuery);
stmt.Close();
conn.Close(); // clean up.
}
catch (any e) {
WriteOutput("Error!<br />");
dump(e.message);
if(IsDefined("stmt")) stmt.Close();
if(IsDefined("conn")) conn.Close();
}
</cfscript>
On 10/25/05, Barney Boisvert <[EMAIL PROTECTED]> wrote:
That's kind of interesting, Doug. Have you (or anyone else) looked to
see if you can get a connection from CF's datasource pool, rather than
building all yourself? Then you could still use CF's datasources for
the portability, but you could roll your own DB access component,
which has various uses, particularly regarding transaction management.
cheers,
barneyb
On 10/25/05, Doug Arthur <[EMAIL PROTECTED]> wrote:
>
> There is a workaround for this using java objects. I'm using the meta data
> from a jdbc connection. Below I'm using getColumnCount & getColumnLabel. I
> also tried dump(rsmd.isNullable(1)); and it returns 0 or 1. I added extra
> code to the udf to demonstrate this.
>
> So, is what I'm demonstrating here what someone is after?
>
> And Sean, isn't there a way to convert a coldfusion recordset into a java
> recordset? I haven't even tried to look, but I figured you might already
> know. Thanks!
>
>
> <cffunction name="dump">
> <cfdump var="#Arguments[1]#">
> </cffunction>
> <cfscript>
> driverClass =
> "macromedia.jdbc.sqlserver.SQLServerDriver";
> serverName = "localhost";
> serverPort = "1433";
> dbname = "db";
> userName = "cfusion";
> password = "password";
>
> try {
> Class = createObject("java"," java.lang.Class").forName(driverClass);
> DriverManager = createObject("java", " java.sql.DriverManager");
> conn = DriverManager.getConnection("jdbc:macromedia:sqlserver://" &
> serverName & ":" & serverPort & ";databaseName=" & dbname, userName,
> Password);
> stmt = conn.createStatement();
>
> rs = stmt.executeQuery("select * from program");
>
>
> // This could be made easier to use the object below instead of the udf,
> but the udf is being used for example purposes.
> // newQuery = CreateObject("java",
> "coldfusion.sql.QueryTable").init(rs);
> // dump(newQuery);
> dump(ResultSettoQuery(rs));
>
> stmt.Close();
> conn.Close(); // clean up.
> }
> catch (any e) {
> WriteOutput("Error!<br />");
> dump(e.message);
> if(IsDefined("stmt")) stmt.Close();
> if(IsDefined("conn")) conn.Close();
> }
>
> function ResultSettoQuery(rs) {
> var rsmd = rs.getMetaData();
> var colCnt = rsmd.getColumnCount ();
> var colList = "";
> var i = 1;
>
> for(i=1;i lte colCnt;i=IncrementValue(i)) {
> colList = ListAppend(colList, rsmd.getColumnLabel(i), ",");
> WriteOutput("<strong>" & ListGetAt(colList, i) & ":</strong><br
> />");
> WriteOutput("IsNullable: " & rsmd.isNullable(i) & "<br />");
> WriteOutput("isAutoIncrement: " & rsmd.isAutoIncrement(i));
> WriteOutput('<br /><br />');
> }
> returnQuery = QueryNew(colList);
>
> while(rs.Next()) {
> QueryAddRow(returnQuery);
> for(i=1;i lte colCnt;i=IncrementValue(i)) {
> QuerySetCell(returnQuery, ListGetAt(colList, i),
> rs.getString (ListGetAt(colList, i)));
> }
> }
> return returnQuery;
> }
> </cfscript>
>
--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/
Got Gmail? I have 100 invites.
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting ( www.cfxhosting.com).
CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm
An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).
CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm
An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
