users@glassfish.java.net

Re: CLOB for LONG String values and OracleConnection from a DataSource

From: Hadraba Petr <hadrabap_at_bluetone.cz>
Date: Tue, 1 Jul 2008 18:09:04 +0200

Hello!

I solved that issue (not for Glassfish actually but because of I hate
Oracle JDBC driver :-o ) by using the DBMS_LOB package.

http://www.psoug.org/reference/dbms_lob.html
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#ARPLS600

You have to create temporary CLOB using DBMS_LOB.CREATETEMPORARY and
finally free that clob using DBMS_LOB.FREETEMPORARY.

Source code:

    static Clob createClob(Connection conn) throws SQLException {
        CallableStatement cStmt = null;
        try {
            cStmt = conn.prepareCall("{ call
dbms_lob.createtemporary(?, TRUE, dbms_lob.session) }");

            cStmt.registerOutParameter(1, Types.CLOB);

            cStmt.execute();

            return cStmt.getClob(1);
        } finally {
            if (cStmt != null) {
                cStmt.close();
            }
        }
    }


    static void freeClob(Connection conn, Clob aClob) throws SQLException {
        CallableStatement cStmt = null;
        try {
            cStmt = conn.prepareCall("{ call dbms_lob.freetemporary(?) }");

            cStmt.setClob(1, aClob);

            cStmt.execute();
        } finally {
            if (cStmt != null) {
                cStmt.close();
            }
        }
    }


Good luck. That's working for me on 10gR2 and 11gR1 and I don't need
Oracle specific classes.

Have a nice day

PETR HADRABA


On Tue, Jul 1, 2008 at 13:11, <glassfish_at_javadesktop.org> wrote:
> Hi
>
> I need to get an OracleConnection in a GF Java module to create a CLOB in order to be able to store large objects ( > 4K bytes). The problem is I cannot get an OracleDataSource to get an OracleConnection. The result of the JNDI lookup is always a com.sun....DataSource.
>
> Does anybody know how to do that?
>
> I've created a JDBC resource and Connection pool in this way:
> <resources>
> <jdbc-resource enabled="true" jndi-name="jdbc/cat" object-type="user" pool-name="catPool">
> <description/>
> </jdbc-resource>
> <jdbc-connection-pool allow-non-component-callers="false"
> associate-with-thread="false" connection-creation-retry-attempts="0"
> connection-creation-retry-interval-in-seconds="10"
> connection-leak-reclaim="false"
> connection-leak-timeout-in-seconds="0"
> connection-validation-method="auto-commit"
> datasource-classname="oracle.jdbc.pool.OracleDataSource"
> fail-all-connections="false" idle-timeout-in-seconds="300"
> is-connection-validation-required="false"
> is-isolation-level-guaranteed="true" lazy-connection-association="false"
> lazy-connection-enlistment="false" match-connections="false"
> max-connection-usage-count="0" max-pool-size="32"
> max-wait-time-in-millis="60000" name="catPool"
> non-transactional-connections="false" pool-resize-quantity="2"
> res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1"
> steady-pool-size="8" validate-atmost-once-period-in-seconds="0"
> wrap-jdbc-objects="false">
> <property name="URL" value="jdbc:oracle:thin:@xxxx.xx:1521:RR12"/>
> <property name="User" value="myuser"/>
> <property name="Password" value="mypasswd"/>
> </jdbc-connection-pool>
> </resources>
>
> I've tested the three possible res-types: javax.sql.DataSource, javax.sql.XADataSource and javax.sql.ConnectionPoolDataSource.
> [Message sent by forum member 'aperezymadrid' (aperezymadrid)]
>
> http://forums.java.net/jive/thread.jspa?messageID=283599
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>