Hi Andy,
You could enable the Connection Validation for the JDBC Connection pool
that is used. There are different validation mechanisms and when "table"
is used as the validation method, a table name could be set to perform
the connection validation.
Please refer
http://blogs.sun.com/JagadishPrasath/entry/connection_validation_in_glassfish_jdbc
for more details on the same.
Thanks,
Shalini.
Andy Knight wrote:
> As far as I know (and please tell me if there's another way) the
> correct generic mechanism for testing the validity of a database
> connection is to use the /isValid() / method of /java.sql.Connection/
> /
> /
> In this example, the underlying DB is Oracle and, of course, one could
> invoke "SELECT * FROM DUAL;" to test the connection. In fact, I
> believe that's what the GlassFish Connection Pool does by default for
> Oracle. However, in principle, I don't know that it's Oracle and so I
> need a generic technique.
>
> /If I acquire a connection from the GlassFish v2.1 Connection Pool and
> invoke /isValid()/, a rather unpleasant Exception occurs. Here's a
> Java code fragment that demonstrates the problem.../
>
> *Connection c = ((DataSource) new
> InitialContext().lookup("jdbc/myOracle")).getConnection();*
> *c.isValid(10);*
> /
>
> ...and here's the Exception...
>
> Caused by: java.lang.AbstractMethodError:
> oracle.jdbc.driver.T4CConnection.isValid(I)Z
> at
> com.sun.gjc.spi.jdbc40.ConnectionHolder40.isValid(ConnectionHolder40.java:196)
> at com.sun.fast.OracleBean.ConnectAndValidate(OracleBean.java:20)
>
> The class com.sun.gjc.spi.jdbc40.ConnectionHolder40 is obviously a
> subclass of java.sql.Connection and is, in fact, the type returned by
> *getConnection()*.
>
> According to the Javadocs for AbstractMethodError...
>
> Thrown when an application tries to call an abstract method. Normally,
> this error is caught by the compiler; this error can only occur at run
> time if the definition of some class has incompatibly changed since
> the currently executing method was last compiled.
>
> How can I work around this?
>
> /
> <http://www.sun.com> Andy Knight
> Principal Engineer,
> Sun Microsystems, Inc.
> Java House, Guillemont Park, Minley Road,
> Camberley, Surrey GU17 9QG United Kingdom
> Home office: +44 1494 462438
> Mobile: +44 7775 583415
> Skype: aprknight
> Email: Andy.Knight_at_Sun.COM <mailto:Andy.Knight_at_Sun.COM>
> Blog: http://blogs.sun.com/andky
> <http://www.sun.com>
>
>