|
Mailing Lists
|
Home /
Groups /
Java
Information about pass Java ResultSet(or QueryTable) to Coldfusion QueryTable
HiAndrea Botta 06/13/07 03:54 A > I have cfc component that implements my Business logic (some sql query)James Holmes 06/13/07 03:59 A Is a business project;Andrea Botta 06/13/07 04:04 A Hi My name's Andrea I'm trying to develop a java class and using it in CFMX 7. I have cfc component that implements my Business logic (some sql query) I want to create a java class to replace this cfc. So, my java class (Pratica.class) return a ColdFusion query object ; I tried to use a solution that i found here http://www.petefreitag.com/item/73.cfm But when ColfFusion execute this code: --------------------------------------------------------------------------------------- <cfset pra = createObject("Java", "Pratica").init(glb,dbprop)> <cfset ourQuery =createObject("java"," coldfusion.sql.QueryTable").init( pra.search())> ---------------------------------------------------------------------------------------- this error occurs: --------------------------------------------------------------------------------------------- An exception occurred when instantiating a java object. The cause of this exception was that: coldfusion/sql/QueryTable. --------------------------------------------------------------------------------------------- If I try to execute Pratica.java with Eclipse I have no problems and all works fine! Also I have tried to return java.sql.ResultSet directly to coldfusion.sql.QueryTable.init () with failure. Can you help me or do you know some other solution? Thank you in advance Andrea Coldfusion developer TESI s.p.a. Italy www.gruppotesi.com Pratica.class --------------------------------------------------------------------------------------------------------------------------------- import java.util.*; import java.sql.*; import coldfusion.sql.*; public class Pratica { private HashMap my; private String URI,LOGIN,PWD,DRIVER; private Connection conn=null; ///////////////////////////////////////////////// //funzione init // //riceve due strutture converite in hashmap // globals // dbprop //////////////////////////////////////////////// public Pratica(HashMap globals,HashMap dbprop) { my = new HashMap(); my.put("GLOBALS",globals); my.put("DBPROP",dbprop); URI = "jdbc:sqlserver://it-bra-s0016;databaseName=nmobl"; LOGIN = "usr_dev"; PWD = "developer"; DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; try{ // Carico il driver JDBC per la connessione con il database MySQL Class.forName(DRIVER); /* Connessione alla base di dati */ conn=DriverManager.getConnection(URI,LOGIN,PWD); if(conn!=null) System.out.println("Connection Successful!"); } catch (ClassNotFoundException e) { // Could not find the database driver System.out.print("\ndriver non trovato "+e.getMessage()); System.out.flush(); } catch (SQLException e) { // Could not connect to the database System.out.print("\nConnessione fallita "+e.getMessage()); System.out.flush(); } } ////////////////////////////////////////////////// //funzione search // //riceve un hash map con i filtri di ricerca ///////////////////////////////////////////////// public QueryTable search(/*HashMap arg*/) { ResultSet rs=null; Statement stmt=null; QueryTable ret=null; String query="SELECT * FROM TAN100pratiche"; try{ stmt = conn.createStatement();// Creo lo Statement per l'esecuzione della query rs=stmt.executeQuery(query); } catch (Exception e) { e.printStackTrace(); } try { ret = Pratica.RsToQueryTable(rs); } catch (SQLException e) { e.printStackTrace(); } return(ret); } ////////////////////////////////////////////////// //conversione resultset to querytable // ////////////////////////////////////////////////// private static QueryTable RsToQueryTable(ResultSet rs) throws SQLException{ return new QueryTable(rs); } ///////////////////////////////////////////// //chiura resultset statament e connessione //////////////////////////////////////////// private void close(){ try{ conn.close(); conn=null; } catch (Exception e) { e.printStackTrace(); } } } ----------------------------------------------------------------------------------------------------------- Coldfusion page ------------------------------------------------------------------------------------------------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Test java class</title> </head> <body> <cftry> <cfset glb_map = createObject("java","java.util.HashMap")> <cfset dbprop_map = createObject("java","java.util.HashMap")> <cfset glb_map.init(glb)> <!---are passed from another page---> <cfset dbprop_map.init(glb["DBPROP"])> <cfset pra = createObject("java","Pratica").init(glb_map,dbprop_map)> <cfset ourQuery =createObject("java","coldfusion.sql.QueryTable").init( pra.search())> <cfcatch> <h2>Error - info below</h2> <cfdump var="#cfcatch#"><cfabort> </cfcatch> </cftry> <h2>Success - statement dumped below</h2> <cfdump var="#ourQuery#"> </body> </html> > I have cfc component that implements my Business logic (some sql query) > I want to create a java class to replace this cfc. Would it be rude to ask "why?" -- mxAjax / CFAjax docs and other useful articles: http://www.bifrost.com.au/blog/ Is a business project; We are tring to convert a cfc to a java class; Can you help me? 2007/6/13, James Holmes <james.holmes@gmail.com>: ----- Excess quoted text cut - see Original Post for more -----
|
May 18, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||