cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alberto Brosich <abros...@ogs.trieste.it>
Subject Re: How to obtain a java.sql.Connection object in a flowscript?
Date Sat, 13 Sep 2008 10:23:58 GMT
Tony Edwards wrote:
> Hi Alberto,
> I'm not too sure about PreparedStatements in Oracle, but I connect to 
> a database using jdbc from flow like this:
>
> function getConnection(){
>    //I obtain these values from an xml file
>    var dbUrl = "jdbc:oracle:thin:@servername:1521:dbname";
>    var dbUSerName = "guest";
>    var dbPassWord = "pwrd";
>
>    try{
>        var jdbc = java.sql.DriverManager.getConnection(dbUrl, 
> dbUserName, dbPassWord)
>    } catch (error) {
>        setMessage("Error conecting to database! " + error);
>        return null;
>    }
>    var conn = new Database(jdbc);
>    return conn;
> }
>
> The line of interest is the "java.sql.DriverManager.getConnection()" 
> which does all the magic. Then I pass this to the Database function in 
> Database.js.
>
> Hope this helps.

Yes, this is a solution. But I wished to use cocoon datasource.
After many attempt I found the following solution:

importClass(Packages.oracle.sql.ARRAY);
importClass(Packages.oracle.jdbc.OracleConnection);

...
var oc = conn.unwrap(OracleConnection); // the way to obtain an 
OracleConnection instance
...
stmt.setArray(idx, oc.createARRAY(SQLTYPE, ArrayValues));
...


SQLTYPE must be an array type defined in your database

This work only with jdbc driver 11g. With older versions you have to 
follow another way, slightly different, using ArrayDescriptor class.

Alberto



>
>
> Alberto Brosich wrote:
>>
>> I need to use PreparedStatement with parameters that are arrays 
>> within a flowscript.
>> Dealing with arrays onto a jdbc connection means use special 
>> functions provided by the jdbc driver.
>> In my case the oracle driver has a function 
>> |*ArrayDescriptor.createDescriptor 
>> <http://www.rakeshv.org/docs/oracle/jdbc3.0/oracle/sql/ArrayDescriptor.html#createDescriptor%28java.lang.String,%20java.sql.Connection%29>*(java.lang.String

>> name, java.sql.Connection conn) that needs a ||java.sql.Connection 
>> connection.
>> Within a flowscript I only know how to obtain a 
>> |org.apache.cocoon.components.flow.javascript.ScriptableConnection 
>> using Database.js from petstore block.
>> I did not found how to have |||java.sql.Connection from it.|
>> I would not use more complicated solutions like hibernate (I have to 
>> do a "simple" select builded in a dynamic way, so using an orm 
>> framework is not so useful) but...
>>
>> Any suggest?
>>
>> Alberto
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message