Firstly, set up a data source that uses the Oracle JDBC drivers. Download the appropriate JAR file and place it in the coldfusion instance's lib
directory and then, through the CFIDE administration panel, you can set up a data source like this:
CF Data Source Name: orcl
JDBC URL: jdbc:oracle:thin:@localhost:1521:orcl
Driver Class: oracle.jdbc.OracleDriver
Driver Name: Other
(Note: the driver name is "Other" not "Oracle" - which would use adobe's Oracle driver not the specified Oracle driver.)
Then you can invoke the stored procedure by dropping down to the raw Java rather than using <cfstoredproc>
or new StoredProc()
.
<cfscript>
array = JavaCast( "string[]", [ 'A', 'B', 'C' ] );
try {
connection = createObject( 'java', 'coldfusion.server.ServiceFactory' )
.getDataSourceService()
.getDataSource( 'orcl' )
.getConnection()
.getPhysicalConnection();
description = createObject( 'java', 'oracle.sql.ArrayDescriptor' )
.createDescriptor( 'STRINGLIST', connection );
oracleArray = createObject( 'java', 'oracle.sql.ARRAY' )
.init( description, connection, array );
statement = connection.prepareCall( '{call test_proc( :input, :output )}' );
statement.setARRAYAtName( "input", oracleArray );
stringType = createObject( 'java', 'java.sql.Types' ).VARCHAR;
statement.registerOutParameter( "output", stringType );
statement.executeQuery();
returnValue = statement.getString( "output" );
}
finally
{
if ( isDefined( "statement" ) )
statement.close();
if ( isDefined( "connection" ) )
connection.close();
}
</cfscript>
As an aside, you can also pass an array to a query (and then get a result you can use in a <cfloop>
) like this:
try {
// set-up connection, etc. as above
statement = connection.prepareStatement( 'SELECT * FROM TABLE( :input )' );
statement.setARRAYAtName( "input", oracleArray );
resultSet = statement.executeQuery();
queryResult = createObject( 'java', 'coldfusion.sql.QueryTable' )
.init( resultSet )
.FirstTable();
}
finally
{
if ( isDefined( "resultSet" ) )
resultSet.close();
if ( isDefined( "statement" ) )
statement.close();
if ( isDefined( "connection" ) )
connection.close();
}