aspose file tools*
The moose likes Tomcat and the fly likes struts 1.3 Data base connection pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "struts 1.3 Data base connection pool" Watch "struts 1.3 Data base connection pool" New topic
Author

struts 1.3 Data base connection pool

vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
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

Joined: Aug 03, 2008
Posts: 9280
    
  17

Nothing to do with Struts. I'll move it to the correct forum (hopefully tomcat forum is the correct place for it)...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15661
    
  15

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".


Customer surveys are for companies who didn't pay proper attention to begin with.
vinod chemmi
Ranch Hand

Joined: Jun 15, 2009
Posts: 35
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

Joined: Jun 25, 2001
Posts: 15661
    
  15

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

Joined: Mar 03, 2008
Posts: 470
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

Joined: Jun 25, 2001
Posts: 15661
    
  15

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

Joined: Jun 15, 2009
Posts: 35
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts 1.3 Data base connection pool
 
Similar Threads
Problem in CMP
connectionTimeout in Tomcat5.5.23
WAS3.5.3 + data source pooling
Connection Pool and Data Source
enterprise application with many users