Wednesday, June 3, 2009

DSN-less ColdFusion queries

<cfscript>
// DNSless DB connection
// http://www.datapackethelp.net/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=47&nav=0
// http://www.ibmpressbooks.com/articles/printerfriendly.asp?p=170336
classLoader = createObject("java", "java.lang.Class");
classLoader.forName("macromedia.jdbc.MacromediaDriver");
dm = createObject("java","java.sql.DriverManager");

con = dm.getConnection("jdbc:macromedia:db2://myserver.com:55000;DatabaseName=SMWDB","username","password");

st = con.createStatement();
rs = st.ExecuteQuery(PreserveSingleQuotes(mySql));
q = createObject("java", "coldfusion.sql.QueryTable").init(rs);

st.close();
con.close();
</cfscript>

No comments: