Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Interest »

Re: JDBC Driver, Context & DataSource lookup

Zumba

2005-08-19

Replies:

I changed it but NOPS!
8-(

On Wed, 2005-08-17 at 09:42 +0800, Frans Verhoef wrote:
> Hi Zumba,
>
> It looks like a typo. Change
>
>          Context env = (Context) initialContext.lookup("java:comp/env");
>
> into
>
>          Context env = (Context) initialContext.lookup("java:/comp/env");
>
> Also, I don't think you need to put the entry in your web.xml file.
>
> Cheers,
> Frans
>
>
> On Tue, 16 Aug 2005 12:22:57 -0300, Zumba wrote:
> >I'm trying to connect to mysql database using InitialContext and
> >DataSource lookup but it not works on FreeBSD 5.4 + tomcat 5.5 +
> >jdk 1.5.0 + mysql-connector-java.jar (3.1.0) installed from ports.
> >The application seems that reads ok the JNDI Resources variables
> >but when I invoke dataSource.getConnection() I get the message on
> >SQLException: "Cannot create JDBC class for
> >'com.mysql.jdbc.Driver'. The fact is if I use
> >DriverManager.getConnection("jdbc:mysql//localhost/mysql?params")
> >without handle mysql-connector-java.jar and your directories it
> >(com.mysql.jdbc.Driver) works fine.
> >
> >---- META-INF/context.xml:
> ><?xml version="1.0" encoding="ISO-8859-1"?>
> ><Context
> >docBase="${catalina.home}/webapps/Grid"
> >path="/Grid"
> >reloadable="true">
> ><Resource
> >name="jdbc/GridDB"
> >type="javax.sql.DataSource"
> >auth="Container"
> >username="grid"
> >password="abc123456"
> >driverClassName="com.mysql.jdbc.Driver"
> >url="jdbc:mysql://localhost/griddb?autoReconnect=true"/></Context>
> >
> >---- the reference on WEB-INF/Web.xml:
> ><resource-ref>
> ><res-ref-name>jdbc/GridDB</res-ref-name><res-
> >type>javax.sql.DataSource</res-type><res-auth>Container</res-auth>
> ></resource-ref>
> >
> >---- servlet code:
> >Context initialContext = new InitialContext();
> >Context env = (Context) initialContext.lookup("java:comp/env");
> >DataSource dataSource = (DataSource) env.lookup("jdbc/GridDB");
> >connection = dataSource.getConnection();
> >
> >Thanks,
> >Zumba
> >
> >______________________________________________________________________
> >_____ To unsubscribe, send email to listserv@(protected)
> >include in the body of the message "signoff SERVLET-INTEREST".
> >
> >Archives: http://archives.java.sun.com/archives/servlet-
> >interest.html Resources:
> >http://java.sun.com/products/servlet/external-resources.html
> >LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> ===========================================================================
> To unsubscribe, send email to listserv@(protected)
> of the message "signoff J2EE-INTEREST". For general help, send email to
> listserv@(protected)".
>
> Esta mensagem foi verificada pelo E-mail Protegido Terra.
> Scan engine: McAfee VirusScan / Atualizado em 16/08/2005 / Verso: 4.4.00/4559
> Proteja o seu e-mail Terra: http://mail.terra.com.br/
>
>

===========================================================================
To unsubscribe, send email to listserv@(protected)
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".
©2008 junlu.com - Jax Systems, LLC, U.S.A.