I think your code should be
Context jndiCntx=getInitialContext();
DataSource ds = (DataSource)jndiCntx.lookup("java:/DefaultDS");
return ds.getConnection();
-----Original Message-----
From: Allan Kamau [SMTP:[EMAIL PROTECTED]]
Sent: Thursday, July 11, 2002 9:02 AM
To: [EMAIL PROTECTED]
Subject: [JBoss-user] How do I obtain a connection from the DefaultDS from my session bean
I am trying to obtain a connection from the DefaultDS,
but I get the error "DefaultDS not Bound".
Below is the code I use to try a bind to the
DefaultDS.
<code>
private Connection getConnection()throws SQLException
{
try
{
Context jndiCntx=getInitialContext();
Object ref=jndiCntx.lookup("DefaultDS");
DataSource
ds=(DataSource)javax.rmi.PortableRemoteObject.narrow(ref,DataSource.class);
return ds.getConnection();
}
catch(NamingException ne)
{
throw new EJBException(ne);
}
}
public static Context getInitialContext()
throws javax.naming.NamingException {
java.util.Properties env=new java.util.Properties();
env.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
env.setProperty("java.naming.provider.url","localhost:1099");
env.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
InitialContext initialContext = new
InitialContext(env);
return initialContext;
}
</code>
Thanks.
__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
PC Mods, Computing goodies, cases & more
http://thinkgeek.com/sf
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user
******************************************************************************** This electronic mail system is used for information purposes and is not intended to form any legal contract or binding agreement. The content is confidential and may be legally privileged. Access by anyone other than the addressee(s) is unauthorised and any disclosure, copying, distribution or any other action taken in reliance on it is prohibited and maybe unlawful All incoming and outgoing e-mail communications and attachments are scanned automatically by software designed to detect and remove any material containing viruses or other unauthorised content. While we undertake best endeavours to ensure that this content checking software is up to date, recipients should take steps to assure themselves that e-mails received are secure. ********************************************************************************