Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts 1.3 Data base connection pool

 
vinod chemmi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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.
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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)...
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic