Re: DBCP Please Help Get Working Properly

2005-04-11 Thread David Smith
Well yes it does make a lot of sense, but is more a question answered by 
design patterns.  It's a little beyond the scope of Tomcat docs to 
address issues like separation of roles.  Both Struts and Spring 
projects address issues like this with the Model-View-Controller (MVC) 
pattern and there are innumerable books on the subject as well.  
Specific to data access methods, Hibernate also addresses this issue.

As far as step by step docs, you are best off picking a framework, 
getting a good book on it and go from there.

Hope this helps.
--David
Scott Purcell wrote:
Thank David for the below information.
This makes some sense, and I will try and make the changes. But this of course 
leads to a follow-up question. Why isn't there any decent documentation to get 
the DBCP running in Tomcat. I am talking about a simple example, that explains 
container versions, jsp versions, possibly better ways to use then putting the 
connection into a JSP page. Connecting in a JSP page is just plain dirty, I 
would like to connect in some class where I can call connections from. Does 
this make sense?
As I mentioned, I followed the example that comes with the documentation for my 
5.5 Tomcat that displays when you go to localhost.
So, is there any good documentation that shows how to do this, step by step?
Thanks,
Scott


-Original Message-
From: David Smith [mailto:[EMAIL PROTECTED]
Sent: Monday, April 11, 2005 8:18 AM
To: Tomcat Users List
Subject: Re: DBCP Please Help Get Working Properly
Ok, define 'no results'. In reality, the naming import isn't the only 
thing that changed. Your web.xml file *looks* like 2.3 spec from what I 
can see and you are using JSP 2.x spec syntax in your jsp. If you want 
the JSP 2.x spec features, you need to declare your web.xml file for 
servlet 2.4 spec. This should be up at the top of your web.xml (pasted 
from the specification for servlet 2.4):


http://java.sun.com/xml/ns/j2ee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”;
version=”2.4”>
Then just put all your servlet-mappings, etc., ... after that. The 
taglib declarations need to be inside a  element for the 2.4 
spec web.xml file too. That's how I'm guessing you have a 2.3 spec 
web.xml file. The full spec can be found at 
http://www.jcp.org/en/jsr/detail?id=154

--David
Scott Purcell wrote:
 

Hello,
I am trying to use the DBCP features of Tomcat 5.5.7. I created a webapp named 
"testDB" and put it under $CATALINA_HOME/webapps/testDB. Then I created a 
testDB.xml file under $CATALINA_HOME/conf/Catalina/localhost/testDB.xml.
// here it is



I have been following the notes from: 
http://localhost/tomcat-docs/jndi-datasource-examples-howto.html

I made sure I completed the rest of the tasks.
WEB-INF has the two tag locations, and the resource ref.
eg:
  
  /WEB-INF/sql.tld
  /WEB-INF/sql.tld
  
  
  /WEB-INF/c.tld
  /WEB-INF/c.tld
  

DB Connection
jdbc/testDB
javax.sql.DataSource
Container

I finally hit my jsp page which is this:
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql"; prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>

select id, foo, bar from testdata



  DB Test


Results

  Foo ${row.foo}
  Bar ${row.bar}



And I get no results:
Now I am pretty sure I have all configured. Because if I use a fallback (Tomcat 
4.1) code piece I had, I get results using the same settings:
package foo;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
public class DBTest {
String foo = "Not Connected";
int bar = -1;
  
public void init() {
  try{
Context ctx = new InitialContext();
if(ctx == null ) 
throw new Exception("Boom - No Context");

DataSource ds = 
  (DataSource)ctx.lookup(
 "java:comp/env/jdbc/testDB");

if (ds != null) {
  Connection conn = ds.getConnection();

  if(conn != null)  {
  foo = "Got Connection "+conn.toString();
  Statement stmt = conn.createStatement();
  ResultSet rst = 
  stmt.executeQuery(
"select id, foo, bar from testdata");
  while(rst.next()) {
 System.out.println("next ");
 foo=rst.getString(2);
 bar=rst.getInt(3);
  }
  conn.close();
  }
}
  }catch(Exception e) {
e.printStackTrace();
  }
}

public String getFoo() { return foo; }
public int getBar() { return bar;}
}
And using the above class works all day.
The only difference I see is that the class using a "naming" import and the jsp 
does not. Can anyone help.
Thanks,
Scott




-Original Message-
From: David Smith [mailto:[EMAIL PROTECTED]
Sent: Friday, April 08, 2005 1:14 PM
To: Tom

RE: DBCP Please Help Get Working Properly

2005-04-11 Thread Scott Purcell
Thank David for the below information.

This makes some sense, and I will try and make the changes. But this of course 
leads to a follow-up question. Why isn't there any decent documentation to get 
the DBCP running in Tomcat. I am talking about a simple example, that explains 
container versions, jsp versions, possibly better ways to use then putting the 
connection into a JSP page. Connecting in a JSP page is just plain dirty, I 
would like to connect in some class where I can call connections from. Does 
this make sense?

As I mentioned, I followed the example that comes with the documentation for my 
5.5 Tomcat that displays when you go to localhost.

So, is there any good documentation that shows how to do this, step by step?


Thanks,
Scott






-Original Message-
From: David Smith [mailto:[EMAIL PROTECTED]
Sent: Monday, April 11, 2005 8:18 AM
To: Tomcat Users List
Subject: Re: DBCP Please Help Get Working Properly


Ok, define 'no results'. In reality, the naming import isn't the only 
thing that changed. Your web.xml file *looks* like 2.3 spec from what I 
can see and you are using JSP 2.x spec syntax in your jsp. If you want 
the JSP 2.x spec features, you need to declare your web.xml file for 
servlet 2.4 spec. This should be up at the top of your web.xml (pasted 
from the specification for servlet 2.4):



http://java.sun.com/xml/ns/j2ee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”;
version=”2.4”>

Then just put all your servlet-mappings, etc., ... after that. The 
taglib declarations need to be inside a  element for the 2.4 
spec web.xml file too. That's how I'm guessing you have a 2.3 spec 
web.xml file. The full spec can be found at 
http://www.jcp.org/en/jsr/detail?id=154

--David

Scott Purcell wrote:

>Hello,
>
>I am trying to use the DBCP features of Tomcat 5.5.7. I created a webapp named 
>"testDB" and put it under $CATALINA_HOME/webapps/testDB. Then I created a 
>testDB.xml file under $CATALINA_HOME/conf/Catalina/localhost/testDB.xml.
>
>// here it is
>debug="5" reloadable="true" crossContext="true">
>
> maxActive="100" maxIdle="30" maxWait="1"
>   username="javauser" password="javadude" 
> driverClassName="com.mysql.jdbc.Driver"
>   url="jdbc:mysql://localhost:3306/fritest?autoReconnect=true"/>
>
>
>I have been following the notes from: 
>http://localhost/tomcat-docs/jndi-datasource-examples-howto.html
>
>I made sure I completed the rest of the tasks.
>WEB-INF has the two tag locations, and the resource ref.
>eg:
>
>
>/WEB-INF/sql.tld
>/WEB-INF/sql.tld
>
>
>
>
>/WEB-INF/c.tld
>/WEB-INF/c.tld
>
>
>  
>  DB Connection
>  jdbc/testDB
>  javax.sql.DataSource
>  Container
>  
>
>I finally hit my jsp page which is this:
><%@ taglib uri="http://java.sun.com/jsp/jstl/sql"; prefix="sql" %>
><%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>
>
>
>select id, foo, bar from testdata
>
>
>
>  
>DB Test
>  
>  
>
>  Results
>  
>
>Foo ${row.foo}
>Bar ${row.bar}
>
>
>
>  
>
>
>And I get no results:
>
>Now I am pretty sure I have all configured. Because if I use a fallback 
>(Tomcat 4.1) code piece I had, I get results using the same settings:
>
>package foo;
>
>import javax.naming.*;
>import javax.sql.*;
>import java.sql.*;
>
>public class DBTest {
>
>  String foo = "Not Connected";
>  int bar = -1;
>
>  public void init() {
>try{
>  Context ctx = new InitialContext();
>  if(ctx == null ) 
>  throw new Exception("Boom - No Context");
>
>  DataSource ds = 
>(DataSource)ctx.lookup(
>   "java:comp/env/jdbc/testDB");
>
>  if (ds != null) {
>Connection conn = ds.getConnection();
>  
>if(conn != null)  {
>foo = "Got Connection "+conn.toString();
>Statement stmt = conn.createStatement();
>ResultSet rst = 
>stmt.executeQuery(
>  "select id, foo, bar from testdata");
>while(rst.next()) {
>   System.out.println("next ");
>   foo=rst.getString(2);
>   bar=rst.getInt(3);
>}
>conn.close();
>}
>  }
>}catch(Exception e) {
&g

Re: DBCP Please Help Get Working Properly

2005-04-11 Thread David Smith
Ok, define 'no results'. In reality, the naming import isn't the only 
thing that changed. Your web.xml file *looks* like 2.3 spec from what I 
can see and you are using JSP 2.x spec syntax in your jsp. If you want 
the JSP 2.x spec features, you need to declare your web.xml file for 
servlet 2.4 spec. This should be up at the top of your web.xml (pasted 
from the specification for servlet 2.4):


http://java.sun.com/xml/ns/j2ee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”;
version=”2.4”>
Then just put all your servlet-mappings, etc., ... after that. The 
taglib declarations need to be inside a  element for the 2.4 
spec web.xml file too. That's how I'm guessing you have a 2.3 spec 
web.xml file. The full spec can be found at 
http://www.jcp.org/en/jsr/detail?id=154

--David
Scott Purcell wrote:
Hello,
I am trying to use the DBCP features of Tomcat 5.5.7. I created a webapp named 
"testDB" and put it under $CATALINA_HOME/webapps/testDB. Then I created a 
testDB.xml file under $CATALINA_HOME/conf/Catalina/localhost/testDB.xml.
// here it is

 

I have been following the notes from: 
http://localhost/tomcat-docs/jndi-datasource-examples-howto.html

I made sure I completed the rest of the tasks.
WEB-INF has the two tag locations, and the resource ref.
eg:
   
   /WEB-INF/sql.tld
   /WEB-INF/sql.tld
   
   
   /WEB-INF/c.tld
   /WEB-INF/c.tld
   
 
 DB Connection
 jdbc/testDB
 javax.sql.DataSource
 Container
 
I finally hit my jsp page which is this:
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql"; prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>

select id, foo, bar from testdata


 
   DB Test
 
 
 Results
 

   Foo ${row.foo}
   Bar ${row.bar}


 

And I get no results:
Now I am pretty sure I have all configured. Because if I use a fallback (Tomcat 
4.1) code piece I had, I get results using the same settings:
package foo;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
public class DBTest {
 String foo = "Not Connected";
 int bar = -1;
   
 public void init() {
   try{
 Context ctx = new InitialContext();
 if(ctx == null ) 
 throw new Exception("Boom - No Context");

 DataSource ds = 
   (DataSource)ctx.lookup(
  "java:comp/env/jdbc/testDB");

 if (ds != null) {
   Connection conn = ds.getConnection();
 
   if(conn != null)  {
   foo = "Got Connection "+conn.toString();
   Statement stmt = conn.createStatement();
   ResultSet rst = 
   stmt.executeQuery(
 "select id, foo, bar from testdata");
   while(rst.next()) {
  System.out.println("next ");
  foo=rst.getString(2);
  bar=rst.getInt(3);
   }
   conn.close();
   }
 }
   }catch(Exception e) {
 e.printStackTrace();
   }
}

public String getFoo() { return foo; }
public int getBar() { return bar;}
}
And using the above class works all day.
The only difference I see is that the class using a "naming" import and the jsp 
does not. Can anyone help.
Thanks,
Scott




-Original Message-
From: David Smith [mailto:[EMAIL PROTECTED]
Sent: Friday, April 08, 2005 1:14 PM
To: Tomcat Users List
Subject: Re: Add Context Path, Tomcat 5.5.7
Hi.
Take a look at this for where to put  elements:
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/context.html
This is new with Tomcat 5.0 and is continued in Tomcat 5.5
--David
Scott Purcell wrote:
 

Hello,
I am following the information here to add DBCP to my application.
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html
I am reading to add the 
Configure the JNDI DataSource in Tomcat by adding a declaration for your 
resource to $CATALINA_HOME/conf/server.xml.
Add this in between the  tag of the examples context and the  
tag closing the localhost definition.

So cool, I opened up the server.xml, but do not see any existing context or 
host tags in it. Here is my server.xml file. Does anyone know where I put the 
Context for the DBCP stuff? Thanks,
'










  
  
  
  




  
  
  
  


  
  

  
  

  
  
  

  
   
   
  
  














   
  
  
  


  
  
  
  
  
  

  




Scott K Purcell | Developer | VERTIS | 
555 Washington Ave. 4th Floor | St. Louis, MO 63101 | 
314.588.0720 Ext:1320 | [EMAIL PROTECTED] | http://www.vertisinc.com   

Vertis is the premier provider of targeted advertising, media, and 
marketing services that drive consumers to marketers more effectively. 
   



   


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands,

RE: DBCP Please Help Get Working Properly

2005-04-08 Thread Jay Burgess
My apologies, we're using 5.0.x and I hadn't realized they went away.  But maybe
the logs still will provide some useful info?

Jay
Vertical Technology Group
http://www.vtgroup.com/


 

-Original Message-
From: Robert Harrison [mailto:[EMAIL PROTECTED] 
Sent: Friday, April 08, 2005 4:20 PM
To: Tomcat Users List
Subject: Re: DBCP Please Help Get Working Properly

Aren't debug levels in TC 5.5  inactive? Will need to set up log4j.

Bob

On Apr 8, 2005 5:15 PM, Jay Burgess <[EMAIL PROTECTED]> wrote:
> Do you have anything in your Tomcat log files that might help?  If not, you 
> can
> bump up the debug levels in server.xml and you might get some more info.
> 
> I also found that adding one of the two following listeners in my server.xml
> helped me debug my DBCP problems (I don't remember which one I added, but it
> should be obvious):
> 
>   className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
>  debug="9"/>
>   className="org.apache.catalina.core.NamingContextListener"
>  debug="9"/>
> 
> Jay
> Vertical Technology Group
> http://www.vtgroup.com/
> 
> 
> -Original Message-----
> From: Scott Purcell [mailto:[EMAIL PROTECTED]
> Sent: Friday, April 08, 2005 3:08 PM
> To: Tomcat Users List
> Subject: DBCP Please Help Get Working Properly
> 
> Hello,
> 
> I am trying to use the DBCP features of Tomcat 5.5.7. I created a webapp named
> "testDB" and put it under $CATALINA_HOME/webapps/testDB. Then I created a
> testDB.xml file under $CATALINA_HOME/conf/Catalina/localhost/testDB.xml.
> 
> // here it is
>  debug="5" reloadable="true" crossContext="true">
> 
>   maxActive="100" maxIdle="30" maxWait="1"
>username="javauser" password="javadude"
> driverClassName="com.mysql.jdbc.Driver"
>url="jdbc:mysql://localhost:3306/fritest?autoReconnect=true"/>
> 
> 
> I have been following the notes from:
> http://localhost/tomcat-docs/jndi-datasource-examples-howto.html
> 
> I made sure I completed the rest of the tasks.
> WEB-INF has the two tag locations, and the resource ref.
> eg:
> 
> 
> /WEB-INF/sql.tld
> /WEB-INF/sql.tld
> 
> 
> 
> /WEB-INF/c.tld
> /WEB-INF/c.tld
> 
> 
>   
>   DB Connection
>   jdbc/testDB
>   javax.sql.DataSource
>   Container
>   
> 
> I finally hit my jsp page which is this:
> <%@ taglib uri="http://java.sun.com/jsp/jstl/sql"; prefix="sql" %>
> <%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>
> 
> 
> select id, foo, bar from testdata
> 
> 
> 
>   
> DB Test
>   
>   
> 
>   Results
> 
> 
> Foo ${row.foo}
> Bar ${row.bar}
> 
> 
>   
> 
> 
> And I get no results:
> 
> Now I am pretty sure I have all configured. Because if I use a fallback 
> (Tomcat
> 4.1) code piece I had, I get results using the same settings:
> 
> package foo;
> 
> import javax.naming.*;
> import javax.sql.*;
> import java.sql.*;
> 
> public class DBTest {
> 
>   String foo = "Not Connected";
>   int bar = -1;
> 
>   public void init() {
> try{
>   Context ctx = new InitialContext();
>   if(ctx == null )
>   throw new Exception("Boom - No Context");
> 
>   DataSource ds =
> (DataSource)ctx.lookup(
>"java:comp/env/jdbc/testDB");
> 
>   if (ds != null) {
> Connection conn = ds.getConnection();
> 
> if(conn != null)  {
> foo = "Got Connection "+conn.toString();
> Statement stmt = conn.createStatement();
> ResultSet rst =
> stmt.executeQuery(
>   "select id, foo, bar from testdata");
> while(rst.next()) {
>System.out.println("next ");
>foo=rst.getString(2);
>bar=rst.getInt(3);
> }
> conn.close();
> }
>   }
> }catch(Exception e) {
>   e.printStackTrace();
> }
>  }
> 
>  public String getFoo() { return foo; }
>  public int getBar() { return bar;}
> }
> 
> And using the above class works all day.
> 
> The only difference I see is that the class using a "naming" import and the 
> jsp
> does not. Can anyone help.
> 
> Thanks,
> Scott
> 
> -Original Message-
> From: David Smi

Re: DBCP Please Help Get Working Properly

2005-04-08 Thread Robert Harrison
Aren't debug levels in TC 5.5  inactive? Will need to set up log4j.

Bob

On Apr 8, 2005 5:15 PM, Jay Burgess <[EMAIL PROTECTED]> wrote:
> Do you have anything in your Tomcat log files that might help?  If not, you 
> can
> bump up the debug levels in server.xml and you might get some more info.
> 
> I also found that adding one of the two following listeners in my server.xml
> helped me debug my DBCP problems (I don't remember which one I added, but it
> should be obvious):
> 
>   className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
>  debug="9"/>
>   className="org.apache.catalina.core.NamingContextListener"
>  debug="9"/>
> 
> Jay
> Vertical Technology Group
> http://www.vtgroup.com/
> 
> 
> -Original Message-
> From: Scott Purcell [mailto:[EMAIL PROTECTED]
> Sent: Friday, April 08, 2005 3:08 PM
> To: Tomcat Users List
> Subject: DBCP Please Help Get Working Properly
> 
> Hello,
> 
> I am trying to use the DBCP features of Tomcat 5.5.7. I created a webapp named
> "testDB" and put it under $CATALINA_HOME/webapps/testDB. Then I created a
> testDB.xml file under $CATALINA_HOME/conf/Catalina/localhost/testDB.xml.
> 
> // here it is
>  debug="5" reloadable="true" crossContext="true">
> 
>   maxActive="100" maxIdle="30" maxWait="1"
>username="javauser" password="javadude"
> driverClassName="com.mysql.jdbc.Driver"
>url="jdbc:mysql://localhost:3306/fritest?autoReconnect=true"/>
> 
> 
> I have been following the notes from:
> http://localhost/tomcat-docs/jndi-datasource-examples-howto.html
> 
> I made sure I completed the rest of the tasks.
> WEB-INF has the two tag locations, and the resource ref.
> eg:
> 
> 
> /WEB-INF/sql.tld
> /WEB-INF/sql.tld
> 
> 
> 
> /WEB-INF/c.tld
> /WEB-INF/c.tld
> 
> 
>   
>   DB Connection
>   jdbc/testDB
>   javax.sql.DataSource
>   Container
>   
> 
> I finally hit my jsp page which is this:
> <%@ taglib uri="http://java.sun.com/jsp/jstl/sql"; prefix="sql" %>
> <%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>
> 
> 
> select id, foo, bar from testdata
> 
> 
> 
>   
> DB Test
>   
>   
> 
>   Results
> 
> 
> Foo ${row.foo}
> Bar ${row.bar}
> 
> 
>   
> 
> 
> And I get no results:
> 
> Now I am pretty sure I have all configured. Because if I use a fallback 
> (Tomcat
> 4.1) code piece I had, I get results using the same settings:
> 
> package foo;
> 
> import javax.naming.*;
> import javax.sql.*;
> import java.sql.*;
> 
> public class DBTest {
> 
>   String foo = "Not Connected";
>   int bar = -1;
> 
>   public void init() {
> try{
>   Context ctx = new InitialContext();
>   if(ctx == null )
>   throw new Exception("Boom - No Context");
> 
>   DataSource ds =
> (DataSource)ctx.lookup(
>"java:comp/env/jdbc/testDB");
> 
>   if (ds != null) {
> Connection conn = ds.getConnection();
> 
> if(conn != null)  {
> foo = "Got Connection "+conn.toString();
> Statement stmt = conn.createStatement();
> ResultSet rst =
> stmt.executeQuery(
>   "select id, foo, bar from testdata");
> while(rst.next()) {
>System.out.println("next ");
>foo=rst.getString(2);
>bar=rst.getInt(3);
> }
> conn.close();
> }
>   }
> }catch(Exception e) {
>   e.printStackTrace();
> }
>  }
> 
>  public String getFoo() { return foo; }
>  public int getBar() { return bar;}
> }
> 
> And using the above class works all day.
> 
> The only difference I see is that the class using a "naming" import and the 
> jsp
> does not. Can anyone help.
> 
> Thanks,
> Scott
> 
> -Original Message-
> From: David Smith [mailto:[EMAIL PROTECTED]
> Sent: Friday, April 08, 2005 1:14 PM
> To: Tomcat Users List
> Subject: Re: Add Context Path, Tomcat 5.5.7
> 
> Hi.
> 
> Take a look at this for where to put  elements:
> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/context.html
> 
> This is new with Tomcat 5.0 and is continued in Tomc

RE: DBCP Please Help Get Working Properly

2005-04-08 Thread Jay Burgess
Do you have anything in your Tomcat log files that might help?  If not, you can
bump up the debug levels in server.xml and you might get some more info.  

I also found that adding one of the two following listeners in my server.xml
helped me debug my DBCP problems (I don't remember which one I added, but it
should be obvious):




Jay
Vertical Technology Group
http://www.vtgroup.com/

 

-Original Message-
From: Scott Purcell [mailto:[EMAIL PROTECTED] 
Sent: Friday, April 08, 2005 3:08 PM
To: Tomcat Users List
Subject: DBCP Please Help Get Working Properly

Hello,

I am trying to use the DBCP features of Tomcat 5.5.7. I created a webapp named
"testDB" and put it under $CATALINA_HOME/webapps/testDB. Then I created a
testDB.xml file under $CATALINA_HOME/conf/Catalina/localhost/testDB.xml.

// here it is


  


I have been following the notes from: 
http://localhost/tomcat-docs/jndi-datasource-examples-howto.html

I made sure I completed the rest of the tasks.
WEB-INF has the two tag locations, and the resource ref.
eg:


/WEB-INF/sql.tld
/WEB-INF/sql.tld




/WEB-INF/c.tld
/WEB-INF/c.tld


  
  DB Connection
  jdbc/testDB
  javax.sql.DataSource
  Container
  

I finally hit my jsp page which is this:
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql"; prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>


select id, foo, bar from testdata



  
DB Test
  
  

  Results
  

Foo ${row.foo}
Bar ${row.bar}



  


And I get no results:

Now I am pretty sure I have all configured. Because if I use a fallback (Tomcat
4.1) code piece I had, I get results using the same settings:

package foo;

import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class DBTest {

  String foo = "Not Connected";
  int bar = -1;

  public void init() {
try{
  Context ctx = new InitialContext();
  if(ctx == null ) 
  throw new Exception("Boom - No Context");

  DataSource ds = 
(DataSource)ctx.lookup(
   "java:comp/env/jdbc/testDB");

  if (ds != null) {
Connection conn = ds.getConnection();
  
if(conn != null)  {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst = 
stmt.executeQuery(
  "select id, foo, bar from testdata");
while(rst.next()) {
   System.out.println("next ");
   foo=rst.getString(2);
   bar=rst.getInt(3);
}
conn.close();
}
  }
}catch(Exception e) {
  e.printStackTrace();
}
 }

 public String getFoo() { return foo; }
 public int getBar() { return bar;}
}

And using the above class works all day.

The only difference I see is that the class using a "naming" import and the jsp
does not. Can anyone help.


Thanks,
Scott









-Original Message-
From: David Smith [mailto:[EMAIL PROTECTED]
Sent: Friday, April 08, 2005 1:14 PM
To: Tomcat Users List
Subject: Re: Add Context Path, Tomcat 5.5.7


Hi.

Take a look at this for where to put  elements:
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/context.html

This is new with Tomcat 5.0 and is continued in Tomcat 5.5

--David

Scott Purcell wrote:

>Hello,
> 
>I am following the information here to add DBCP to my application.
>http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html
> 
>I am reading to add the  
>Configure the JNDI DataSource in Tomcat by adding a declaration for your
resource to $CATALINA_HOME/conf/server.xml.
>
>Add this in between the  tag of the examples context and the 
tag closing the localhost definition.
>
> 
>
>So cool, I opened up the server.xml, but do not see any existing context or
host tags in it. Here is my server.xml file. Does anyone know where I put the
Context for the DBCP stuff? Thanks,
>
>'
>
> 
>
> 
>
> 
>  
>  
>  
>  
> 
>  
>  
> 
>
>
> 
>
>  type="org.apache.catalina.UserDatabase"
>   description="User database that can be updated and saved"
>   factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
>  pathname="conf/tomcat-users.xml" />
> 
>  
> 
>  
> 
>  
>  
> 
>
> 
>
>port="80"   maxThreads="150" minSpareThreads="25" 
>maxSpareThreads="75"
>   enableLookups="false" redirectPort="8443" acceptCount="100"
>   connectionTimeout="2" disableUploadTimeout="true"

DBCP Please Help Get Working Properly

2005-04-08 Thread Scott Purcell
Hello,

I am trying to use the DBCP features of Tomcat 5.5.7. I created a webapp named 
"testDB" and put it under $CATALINA_HOME/webapps/testDB. Then I created a 
testDB.xml file under $CATALINA_HOME/conf/Catalina/localhost/testDB.xml.

// here it is


  


I have been following the notes from: 
http://localhost/tomcat-docs/jndi-datasource-examples-howto.html

I made sure I completed the rest of the tasks.
WEB-INF has the two tag locations, and the resource ref.
eg:


/WEB-INF/sql.tld
/WEB-INF/sql.tld




/WEB-INF/c.tld
/WEB-INF/c.tld


  
  DB Connection
  jdbc/testDB
  javax.sql.DataSource
  Container
  

I finally hit my jsp page which is this:
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql"; prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>


select id, foo, bar from testdata



  
DB Test
  
  

  Results
  

Foo ${row.foo}
Bar ${row.bar}



  


And I get no results:

Now I am pretty sure I have all configured. Because if I use a fallback (Tomcat 
4.1) code piece I had, I get results using the same settings:

package foo;

import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class DBTest {

  String foo = "Not Connected";
  int bar = -1;

  public void init() {
try{
  Context ctx = new InitialContext();
  if(ctx == null ) 
  throw new Exception("Boom - No Context");

  DataSource ds = 
(DataSource)ctx.lookup(
   "java:comp/env/jdbc/testDB");

  if (ds != null) {
Connection conn = ds.getConnection();
  
if(conn != null)  {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst = 
stmt.executeQuery(
  "select id, foo, bar from testdata");
while(rst.next()) {
   System.out.println("next ");
   foo=rst.getString(2);
   bar=rst.getInt(3);
}
conn.close();
}
  }
}catch(Exception e) {
  e.printStackTrace();
}
 }

 public String getFoo() { return foo; }
 public int getBar() { return bar;}
}

And using the above class works all day.

The only difference I see is that the class using a "naming" import and the jsp 
does not. Can anyone help.


Thanks,
Scott









-Original Message-
From: David Smith [mailto:[EMAIL PROTECTED]
Sent: Friday, April 08, 2005 1:14 PM
To: Tomcat Users List
Subject: Re: Add Context Path, Tomcat 5.5.7


Hi.

Take a look at this for where to put  elements:
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/context.html

This is new with Tomcat 5.0 and is continued in Tomcat 5.5

--David

Scott Purcell wrote:

>Hello,
> 
>I am following the information here to add DBCP to my application.
>http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html
> 
>I am reading to add the instructions say to ".
> 
>Configure the JNDI DataSource in Tomcat by adding a declaration for your 
>resource to $CATALINA_HOME/conf/server.xml.
>
>Add this in between the  tag of the examples context and the  
>tag closing the localhost definition.
>
> 
>
>So cool, I opened up the server.xml, but do not see any existing context or 
>host tags in it. Here is my server.xml file. Does anyone know where I put the 
>Context for the DBCP stuff? Thanks,
>
>'
>
> 
>
> 
>
> 
>  
>  
>   className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
>   className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
> 
>  
>  
> 
>
>
> 
>
>  type="org.apache.catalina.UserDatabase"
>   description="User database that can be updated and saved"
>   factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
>  pathname="conf/tomcat-users.xml" />
> 
>  
> 
>  
> 
>  
>  
> 
>
> 
>
>port="80"   maxThreads="150" minSpareThreads="25" 
>maxSpareThreads="75"
>   enableLookups="false" redirectPort="8443" acceptCount="100"
>   connectionTimeout="2" disableUploadTimeout="true" />
>
> 
> 
> 
>
>
> 
>
>   enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
> 
>
>
>
> 
>
> 
> 
> 
>
>
> 
>  
>  
> 
>  
> 
>  
>   resourceName="UserDatabase"/>
> 
>  
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> unpackWARs="true" autoDeploy="true"
>   xmlValidation="false" xmlNamespaceAware="false">
> 
> 
>
>
>
> 
> 
> 
>
>
> 
>
>
> 
>
>
> 
>  
> 
>
> 
>  
> 
>
>
>
> 
>
> 
>
>Scott K Purcell | Developer | VERTIS | 
>555 Washington Ave. 4th Floor | St. Louis, MO 63101 | 
>314.588.0720 Ext:1320 | [EMAIL PROTECTED] | http://www.vertisinc.com 
>