users@glassfish.java.net

Problem while using JNDI-Datasource in Glassfish

From: <glassfish_at_javadesktop.org>
Date: Wed, 07 May 2008 22:32:38 PDT

Hi,

   In my project I need to connect to MySQL database
through JDBC (Datasource, connection pool etc.,).

For that, I have created Datasource (mySource). and
a connection pool (myConnectionPool)..

when I am using ping (from Glassfish), the connection pool is working fine.

Problem is when I try to access database from inside my
code.. it gives following error,

[i][b]com.sun.gjc.spi.jdbc40.ConnectionHolder40 cannot be cast to com.mysql.jdbc.Connection
[/b][/i]

after the line
[i]
        Connection con = ds.getConnection();
[/i]

Following is the related code segment...

[i]
/* Related Imports are as follows */

import com.mysql.jdbc.Connection;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;


        ...................................
        ...................................

        Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/myDatasource");
        Connection con = ds.getConnection();
        con.setAutoCommit(true);

        Statement stmt = con.createStatement();

        ResultSet rs = stmt.executeQuery("select * from myTable");
        ...................................
        ...................................
[/i]

kindly suggest the some solution for this...

Thanks,
P.Vallinayagam
[Message sent by forum member 'vallinayagam_p_r' (vallinayagam_p_r)]

http://forums.java.net/jive/thread.jspa?messageID=273253