1.  Configure your container (Tomcat, it appears for you) to resolve a JNDI
name to your datasource (database or LDAP server).  I just started using
Tomcat again after 2 years, so I forgot just how to do this (I just bought
James Goodwill's "Jakarta Apache Tomcat" (O'Reilly Dec. 2001 - covers 4.x -
but I haven't cracked it yet).  It's probably a combination of one or more
files in the %CATALINA_HOME%/config directory.  There will be a tag to
associate a JNDI name with the datasource.  You can call it anything you
want, but conventionally it's something like "jdbc/myDatasourceName."

2.  Create a class (value object, session bean, JavaBean, etc.) to
instantiate a connection and query the datasource:

  import java.util.*;
  import java.sql.*;
  import java.io.*;

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

  public class MyDataObject implements serializable {
    public void getData() throws IOException, SQLException {
        Connection conn = null;
      DataSource ds = null;
      OutputStream out = null;
      
      try {
        Context ic = new InitialContext();
        ds = (DataSource) ic.lookup( "jdbc/myDatasourceName");
        conn = ds.getConnection();
        // query and return data through the Connection object, 
        // probably to a static java.util.Properties object
      } catch( NamingException e) {
        e.printStackTrace();
      } finally {
        // cleanup
      }
    }
  }

3.  Call this object from a Struts Action class:

  Properties props = MyDataObject.properties;

and use props as you will.

Mark


-----Original Message-----
From: Vincent Stoessel [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 10, 2002 12:14 PM
To: Struts Users Mailing List
Subject: Re: jndi as a data source


I thought it might be cool to use ldap as an authetication mechanism.
Yeah, I saw the tomcat jndi how-to.
I could have sworn that I saw jndi used as a datasource but I could 
haave been tired on that day. I'm still a struts newbie, so I wouldn't 
know how to do cool struts authetication with regular JDBC either.  :)


Galbreath, Mark wrote:
> JNDI operates through your container environment, not Struts.  You can get
> that information from your app server's docs (specifically) or from
> java.sun.com (generally). What, specifically do you need to know?
> 
> Mark
> 
> -----Original Message-----
> From: Vincent Stoessel [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 10, 2002 10:26 AM
> To: Struts Users
> Subject: jndi as a data source
> 
> 
> Hello All,
> I'm cuurently searching but can't seem to find a page with an example
> jndi example for struts. I have to build a quick demo app for the suits.
:)
> Any pointers or clue bricks will be appreciated.
> Thanks in advance.
> 
> 


-- 
Vincent Stoessel
Linux Systems Developer
vincent xaymaca.com

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

Reply via email to