Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

struts 1.3 Data base connection pool

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I tried to make database connection pool using DataSource configuration in tomcat's server.xml file.But failed to access the data source from jsp's.
I am getting Exception "Name jdbc is not bound in this Context ".How to resolve it?

Thanks in advance.
 
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing to do with Struts. I'll move it to the correct forum (hopefully tomcat forum is the correct place for it)...
 
Saloon Keeper
Posts: 24886
174
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're probably trying to look up the datasource using a URL such as "java:comp/env/jdbc/mydsrc". When JNDI cannot locate a named resource, it returns a message telling to at what point in the URL the trail ran out. It's saying that it couldn't find a "/jdbc" level node, so basically, you haven't managed to define the datasource to Tomcat in a way that's visible to that particular web application. Check your connection pool definition. It needs to be defining a resource named "jdbc/mydsrc".
 
vinod chemmi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am using tomcat6,NetBeans 6.8 and struts 1.3. I am trying to configure JNDI data source in tomcat's conf/server.xml file .Below giving the details.


In conf/server.xml

<Context path="/Job" docBase="Job" reloadable="true" crossContext="true">
<Resource name="jdbc/job" auth="Container" scope="Shareable"
type="javax.sql.DataSource" maxActive="-1" maxIdle="-1" maxWait="10000"
username="root" password="" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/Job?autoReconnect=true"/>
</Context>

In web.xml

<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/job</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

And from JSP page

InitialContext ctx=new InitialContext();
Context envCtx=(Context)ctx.lookup("java:comp/env");
DataSource ds=(DataSource)envCtx.lookup("jdbc/job");
Connection con=ds.getConnection();

I am getting the exception
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'

Thanks.



 
Tim Holloway
Saloon Keeper
Posts: 24886
174
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hate that one. I think it's one of the "big 4" parameters. You've miscoded something. I'm suspecting that you should have coded "userName=", not "username=", but I'm too lazy to check.
 
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vinod chemmi wrote:I am using tomcat6,NetBeans 6.8 and struts 1.3. I am trying to configure JNDI data source in tomcat's conf/server.xml file .Below giving the details.

In conf/server.xml



Just for your information

For Tomcat 6, unlike Tomcat 4.x, it is NOT recommended to place <Context> elements directly in the server.xml file. This is because it makes modifying the Context configuration more invasive since the main conf/server.xml file cannot be reloaded without restarting Tomcat.

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
 
Tim Holloway
Saloon Keeper
Posts: 24886
174
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to see that someone's been reading the instructions.

Actually, it's reasonable to put something in server.xml if it's intended to apply to more than one Context. However, you're quite correct. Contexts and their sub-elements should not be placed within server.xml. Now somebody please tell the Eclipse WTP people that!
 
vinod chemmi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Buddy

I resolved the issue.
1.add mysql-connector in lib.
2.check Tools->Server->classe node,for mysql-connector jar added or not. If not go back Project node and deploy.
this should be there in classes of Server.
3.In META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/Job">
<Resource name="jdbc/job" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/Job"/>
</Context>
4.in WEB-INF/web.xml
<resource-ref>
<description>dbcp</description>
<res-ref-name>jdbc/job</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

5.Then from JSP's

InitialContext ctx=new InitialContext();
Context envCtx=(Context)ctx.lookup("java:comp/env");
DataSource ds=(DataSource)envCtx.lookup("jdbc/job");
Connection con=ds.getConnection();

Thanks. It spoiled my three days.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic