Ok guys, here we are. I have define the new resource inside a <Context> tag
inside a <Host> tag, as suggested by Tomcat documentation. I removed it and
put it inside <GlobalNamingResources> tag like the following:

1. Configure naming Resource:
    inside <GlobalNamingResources> i put the following:
<Resource name="jdbc/DBTest" auth="Container" type="javax.sql.DataSource"
                          maxActive="100" maxIdle="30" maxWait="10000"
                          username="root" password="exam" driverClassName="
com.mysql.jdbc.Driver"
                      url="jdbc:mysql://localhost:3306/exam"/>

2. Inside web.xml:
<resource-ref>
      <description>Oracle Datasource example</description>
      <res-ref-name>jdbc/DBTest</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
    </resource-ref>

3. Finally, you have to connect your server to the new resource. To do that,
inside context.xml put the following:
<ResourceLink global="jdbc/DBTest" name="jdbc/DBTest" type="
javax.sql.DataSource"/>

4. Test your code as follow:

<%@ page import = "java.sql.*, javax.naming.*, javax.sql.*" %>

<%

      Context initContext = new InitialContext();
       DataSource ds  =
      (DataSource)initContext.lookup("java:comp/env/jdbc/DBTest");

       Connection conn = ds.getConnection();

       out.println("Connection Established");

%>
Tomcat 6 documentation stated that you have to put naming resource
definition inside the Context tag. And this was the problem, when i removed
it from their it worked find and the connection established successfully.

Anyways, thank you very much buddies for your time and consideration. I am
always saying that the user of this mailing list are the best developers in
the world. ;)

On 7/26/07, Christopher Schultz <[EMAIL PROTECTED]> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Mohammed,
>
> Mohammed Zabin wrote:
> > If you looked at the exception you will find ClassNotFoundException at
> line
> > 66 in the generated servlet, and this occurs withing the try block, so,
> i
> > think it's a problem of Connector.
>
> You are seriously confused, here.
>
> Your code is not being compiled. Your code is not running. The fact that
> you have a try/catch block in your code is irrelevant.
>
> Why do you think that this "occurs" within the try block? Your stack
> trace does not include any references to your own code. It's simply not
> executing.
>
> And, even if this "occurred" within your try/catch block, you are
> foolishly swallowing all exceptions, meaning that you would never know
> what the problem was.
>
> > But the strange thing is that this
> > code worked fine on a normal java class???
>
> Probably because your "normal java class" actually compiled and ran.
> Something is wrong with your file, not your code.
>
> - -chris
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGqO9T9CaO5/Lv0PARAuXgAKDBgPM+osNL0y15at28q9YITixicACgqJte
> QOgTrjE+1cqeih2be83XEww=
> =dPUB
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to