DataSource has more to do with jndi rather than jini (afaik)!

Datasources are usually configured in and provided by j2ee application servers and are bound to jndi with a certain name.

As a client you must do several steps to get hands on a datasource and therefore a connetion:

1.Get a jndi InitialContext (here you must provide valid environment for your configuration, like INITIAL_CONTEXT_FACTORY and PROVIDER_URL)
2. Retrive Object from your InitialContext by name, this would be your fsName in case you bound the DataSource to this name
3. Cast object to DataSource
4. Call ds.getConnection() to get a Connection. There are certain things to observe (=transaction config, trans. control) on connections which are retrieved like this if your in context of an ejb, so becarefull.
5. With this connection you can call sql on your db the usuall jdbc-way.
6. DO Never forget to close this connection. In most cases a DataSource is backed up by jdbc connection pool. With closing your connection the pool-connection is given back to the pool. (Use try-finally and connection.close() in finally-block).

Sincerely,
Peter
 

Tom & Sharon Kochanowicz wrote:

I am trying to get a Data Source to work with Tomcat 4 and JSDK 1.4-beta. I understand that the JSDK-1.4 has jini included. My error is Data Source not Found. What do I need to do to get Tomcat 4 to connect to DB 7.2 using a data source? Here is the relevant servlet code. (The code compiles fine).

Tom K.

import javax.servlet.*;

import javax.naming.* ;

import java.sql.* ;

import javax.sql.DataSource ;

public class SimpleDigest extends HttpServlet {

private DataSource ds ;

////private String fsName = "jdbc/pjtutorial/db2";

private String fsName = "TEST";

private String querySQL = "SELECT id, title, author FROM digest" ;

--

Peter Huber
(IT Consultant)

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

evodion Information Technologies
GmbH & Co KG
Geschäftsstelle München
Witneystr.1
D-82008 Unterhaching
Telefon: +49-89-66561 - 128
Fax:     +49-89-66561 - 199
e-mail: mailto:[EMAIL PROTECTED]
Germany Web: http://www.evodion.de
  ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to