tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Morgan Delagrange" <mdela...@yahoo.com>
Subject Re: DB connection tag question
Date Thu, 16 Aug 2001 19:31:30 GMT

----- Original Message -----
From: "Karen E. Lee" <karenlee@nersp.nerdc.ufl.edu>
To: <taglibs-user@jakarta.apache.org>
Sent: Thursday, August 16, 2001 1:26 PM
Subject: DB connection tag question


> I am using DBTags in an app I'm working on... very simple, just one jsp
page.  I am confused about how to use a datasource to get the connection. In
the API it says
>
> "The connection tag also accepts a reference to a Servlet attribute
containing a javax.sql.DataSource object. (The attribute is found via the
findAttribute() method of PageContext.):"
>
> I have used scriptlets to create a DataSource object from a JNDI named
connection pool:
>
>       <% Hashtable params = new Hashtable(); %>
>       <% params.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.ejs.ns.jndi.CNInitialContextFactory"); %>
>       <% Context ctx = new javax.naming.InitialContext(params); %>
>       <% javax.sql.DataSource ds = (javax.sql.DataSource)
ctx.lookup("jdbc/mydatabase"); %>
>
> How do I now use this DataSource in my connection tag?
> Thanks.
>

Then you have to assign it to a servlet attribute:

  <% pageContext.setAttribute("ds1", ds); %>

and then reference that DataSource attibute in the connection tag:

  <sql:connection id="conn1" dataSource="ds1"/>

or you could pass the jndiName in via the jndiName attribute to the
connection tag, but I don't know too much about that.

- Morgan


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Mime
View raw message