cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Rusnak <m...@cyberspace.sk>
Subject Re: Getting database connection in flow script
Date Sat, 23 Oct 2004 10:42:56 GMT
>> I am using CForms/flow-script. When the form is submited, I usually call
>> a methods in my database utility classes from flow-script to perform a
>> DB queries. For that I need to obtain a database connection from the
>> pool. I tried the method: Database.getConnection("connection-id"), but
>> it returns ScriptableConnection class. Is it possible to get reference
>> to java.sql.Connection in flow-script? What is the preferred way to
>> handle database calls in flow-script?
> 
> 
> Martin,
> 
> I don't see why it's not possible to get a Connection the normal way in 
> Flowscript.
> 
> There is no "preferred way" to do it; you're free to do it however you 
> want.  You could probably hide it behind a simple facade written in 
> Java.  You can instantiate normal Java classes in Flowscript.  See: 
> http://cocoon.apache.org/2.1/userdocs/flow/java.html

Tonny,

I'll provide an example code snippets:

In file DBUtil.java:

public static void register(Connection con, String username, String password)
throws SQLException {

    // JDBC calls

}

In file registration.js:

function registration() {

    var form = new Form("forms/registration.xml");

    form.showForm("registration-display-pipeline");

    var model = form.getModel();

    var conn = null;
    try {
        conn = Database.getConnection("ser-connection");
        DBUtil.register(conn, model.username, model.password);
    } catch(ex) {
        cocoon.log.error(ex)
    } finally {
        if(conn != null)conn.close()
    }
    
    cocoon.sendPage("success.html");
}

When running the form, the following exception occurred:

org.mozilla.javascript.EvaluatorException: Cannot convert org.apache.cocoon.components.flow.javascript.ScriptableConnection@1cd3dd7
to java.sql.Connection

So the register() method requires java.sql.Connection as a parameter but the
Database.getConnection() in flow-script returns ScriptableConnection object.


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


Mime
View raw message