Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Connecting to DB using Tomcat and Datasource

843859Nov 16 2006 — edited May 24 2007
I want to use a Datasource to connect to my SQL database so I can use the connection pooling.

So I downloaded the latest version of tomcat installed it and did the following MySQL DBCP Example

http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

then ran the JSP file http://localhost:8080/DBTest/test.jsp and it worked fine.

Now I need to know exactly what I need to do in my Java app to obtain a datasource.

I tried adding these 2 lines but get this error.
    InitialContext ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/DBTest");
need to specify class name in environment.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 21 2007
Added on Nov 16 2006
39 comments
2,384 views