You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Darryl Wagoner <da...@mason-nh.net> on 2005/03/08 15:32:19 UTC

getting datasource in a JSP?

Greetings,

I am trying to follow some of the examples and got some more questions 
and problems.

I think the main problem is that I haven't found the import for the 
Context class.  Should
this a class in common/lib to get the connection?

thanks

<%@ page
    import = "java.io.*"
    import = "java.lang.*"
    import = "java.sql.*"
%>

<%

    //Context ctx = null;
    javax.sql.DataSource rofDS = null;

    try
    {
//      ctx = new InitialContext();
        //rofDS = (javax.sql.DataSource)ctx.lookup("rofDB");
    }
    catch (Exception ne)
          {
          ne.printStackTrace();
          }
%>


-- 
Darryl Wagoner - WA1GON

"Evil triumphs when good men do nothing."  - Edmund Burke [1729-1797]

Join the TrustedQSL mailing list.  An Open Source solution.
Post message: TrustedQSL@yahoogroups.com Subscribe:  TrustedQSL-subscribe@yahoogroups.com List owner:  TrustedQSL-owner@yahoogroups.com http://www.trustedQSL.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: getting datasource in a JSP?

Posted by Darryl Wagoner <da...@mason-nh.net>.
Peter Johnson wrote:

> As shown in the examples
>
>    Context initContext = new InitialContext();
>    Context envContext  = (Context)initContext.lookup("java:/comp/env");
>    DataSource ds = (DataSource)envContext.lookup("jdbc/rofDB");

Thanks for the quick reply!  That has solved the problem!


-- 
Darryl Wagoner - WA1GON

"Evil triumphs when good men do nothing."  - Edmund Burke [1729-1797]

Join the TrustedQSL mailing list.  An Open Source solution.
Post message: TrustedQSL@yahoogroups.com Subscribe:  TrustedQSL-subscribe@yahoogroups.com List owner:  TrustedQSL-owner@yahoogroups.com http://www.trustedQSL.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: getting datasource in a JSP?

Posted by Peter Johnson <pe...@wizardslair.net>.
As shown in the examples
 
    Context initContext = new InitialContext();
    Context envContext  = (Context)initContext.lookup("java:/comp/env");
    DataSource ds = (DataSource)envContext.lookup("jdbc/rofDB");

Parsons Technical Services wrote:

> Try "jdbc/rofDB"
>
>
>
> Doug
>
>
> ----- Original Message ----- From: "Darryl Wagoner" 
> <da...@mason-nh.net>
> To: "Tomcat Users List" <to...@jakarta.apache.org>
> Sent: Tuesday, March 08, 2005 4:15 PM
> Subject: Re: getting datasource in a JSP?
>
>
>> Rahul Akolkar wrote:
>>
>>> javax.naming.Context
>>>
>> Thank Rahul that help, but now I have another problem.  When I use 
>> the tomcat example JSP tags page:
>>
>> This works!!!!
>> ******************************************************************************* 
>>
>>
>> <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
>> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
>>
>> <sql:query var="rs" dataSource="rofDB">
>> select id, foo, bar from testdata
>> </sql:query>
>>
>> <html>
>>  <head>
>>    <title>DB Test</title>
>>  </head>
>>  <body>
>>
>>  <h2>Results</h2>
>>
>> <c:forEach var="row" items="${rs.rows}">
>>    Foo ${row.foo}<br/>
>>    Bar ${row.bar}<br/>
>> </c:forEach>
>> ********************************************
>> The following throws:
>>
>> Name rofDB is not bound in this Context.
>>
>> Please Help!
>>
>> thanks
>>
>> ************************************************************************************** 
>>
>> <%@ page
>>    import = "java.io.*"
>>    import = "java.lang.*"
>>    import = "java.sql.*"
>>    import = "javax.naming.*"
>>    import = "java.util.*"
>>
>> %>
>> <%
>>
>>    Context ctx = null;
>>    javax.sql.DataSource rofDS = null;
>>
>>    try
>>    {
>>        java.util.Date now = new java.util.Date();
>>        ctx = new InitialContext();
>>        out.println("before lookup " + now + "<br>");
>>        rofDS = (javax.sql.DataSource)ctx.lookup("/rofDB");
>>        out.println("after lookup<br>");
>>    }
>>    catch (Exception ne)
>>          {
>>          out.println(ne.getMessage());
>>          }
>> %>
>>
>>
>> -- 
>> Darryl Wagoner - WA1GON
>>
>> "Evil triumphs when good men do nothing."  - Edmund Burke [1729-1797]
>>
>> Join the TrustedQSL mailing list.  An Open Source solution.
>> Post message: TrustedQSL@yahoogroups.com Subscribe: 
>> TrustedQSL-subscribe@yahoogroups.com List owner: 
>> TrustedQSL-owner@yahoogroups.com http://www.trustedQSL.org
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: getting datasource in a JSP?

Posted by Parsons Technical Services <pa...@earthlink.net>.
Try "jdbc/rofDB"



Doug


----- Original Message ----- 
From: "Darryl Wagoner" <da...@mason-nh.net>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Tuesday, March 08, 2005 4:15 PM
Subject: Re: getting datasource in a JSP?


> Rahul Akolkar wrote:
>
>>javax.naming.Context
>>
> Thank Rahul that help, but now I have another problem.  When I use the 
> tomcat example JSP tags page:
>
> This works!!!!
> *******************************************************************************
>
> <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
>
> <sql:query var="rs" dataSource="rofDB">
> select id, foo, bar from testdata
> </sql:query>
>
> <html>
>  <head>
>    <title>DB Test</title>
>  </head>
>  <body>
>
>  <h2>Results</h2>
>
> <c:forEach var="row" items="${rs.rows}">
>    Foo ${row.foo}<br/>
>    Bar ${row.bar}<br/>
> </c:forEach>
> ********************************************
> The following throws:
>
> Name rofDB is not bound in this Context.
>
> Please Help!
>
> thanks
>
> **************************************************************************************
> <%@ page
>    import = "java.io.*"
>    import = "java.lang.*"
>    import = "java.sql.*"
>    import = "javax.naming.*"
>    import = "java.util.*"
>
> %>
> <%
>
>    Context ctx = null;
>    javax.sql.DataSource rofDS = null;
>
>    try
>    {
>        java.util.Date now = new java.util.Date();
>        ctx = new InitialContext();
>        out.println("before lookup " + now + "<br>");
>        rofDS = (javax.sql.DataSource)ctx.lookup("/rofDB");
>        out.println("after lookup<br>");
>    }
>    catch (Exception ne)
>          {
>          out.println(ne.getMessage());
>          }
> %>
>
>
> -- 
> Darryl Wagoner - WA1GON
>
> "Evil triumphs when good men do nothing."  - Edmund Burke [1729-1797]
>
> Join the TrustedQSL mailing list.  An Open Source solution.
> Post message: TrustedQSL@yahoogroups.com Subscribe: 
> TrustedQSL-subscribe@yahoogroups.com List owner: 
> TrustedQSL-owner@yahoogroups.com http://www.trustedQSL.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: getting datasource in a JSP?

Posted by Darryl Wagoner <da...@mason-nh.net>.
Rahul Akolkar wrote:

>javax.naming.Context
>  
>
Thank Rahul that help, but now I have another problem.  When I use the 
tomcat example JSP tags page:

This works!!!!
*******************************************************************************

<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<sql:query var="rs" dataSource="rofDB">
select id, foo, bar from testdata
</sql:query>

<html>
  <head>
    <title>DB Test</title>
  </head>
  <body>

  <h2>Results</h2>

<c:forEach var="row" items="${rs.rows}">
    Foo ${row.foo}<br/>
    Bar ${row.bar}<br/>
</c:forEach>
********************************************
The following throws:

Name rofDB is not bound in this Context.

Please Help!

thanks

**************************************************************************************
<%@ page
    import = "java.io.*"
    import = "java.lang.*"
    import = "java.sql.*"
    import = "javax.naming.*"
    import = "java.util.*"

%>
<%

    Context ctx = null;
    javax.sql.DataSource rofDS = null;

    try
    {
        java.util.Date now = new java.util.Date();
        ctx = new InitialContext();
        out.println("before lookup " + now + "<br>");
        rofDS = (javax.sql.DataSource)ctx.lookup("/rofDB");
        out.println("after lookup<br>");
    }
    catch (Exception ne)
          {
          out.println(ne.getMessage());
          }
%>


-- 
Darryl Wagoner - WA1GON

"Evil triumphs when good men do nothing."  - Edmund Burke [1729-1797]

Join the TrustedQSL mailing list.  An Open Source solution.
Post message: TrustedQSL@yahoogroups.com Subscribe:  TrustedQSL-subscribe@yahoogroups.com List owner:  TrustedQSL-owner@yahoogroups.com http://www.trustedQSL.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: getting datasource in a JSP?

Posted by Rahul Akolkar <ra...@gmail.com>.
javax.naming.Context

On Tue, 08 Mar 2005 09:32:19 -0500, Darryl Wagoner
<da...@mason-nh.net> wrote:

<snip>
> I think the main problem is that I haven't found the import for the
> Context class.
<snap>

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org