You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Mark A. Richman" <ma...@markrichman.com> on 2001/12/26 15:57:02 UTC

Using JNDI from Web Service

Hi all!!!
 
Is it possible to reference a JNDI object from a web service's
implementation class? For example, I have a class I wish to expose as a
web service. This class is currently accessing a HypersonicSQL
DataSource using the usual "Class.forName("org.hsqldb.jdbcDriver")" and
associated DriverManager.getConnection() contructs.
 
How can I define a JDBC DataSource using JNDI and gain access to it from
my web service implementation?
 
Presumably, I'd want to replace all the prior code with something like
this:
 
InitialContext ctx = new InitialContext();
DataSource ds =
(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/MyDataSource");
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
 
 
Thanks,
Mark A. Richman
http://www.markrichman.com <http://www.markrichman.com/>