You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Scott Van Wart <sc...@indosoft.com> on 2006/08/24 22:35:27 UTC

Re: [JAVA]How to get datatbase connection from lookup to datatsource name in a standalone java application

temp temp wrote:
> My java standalone application wants connection to database with lookup  to datasource name which is configured in the oc4j app server. 
>   Please guide me with some ideas to achieve this.
>   
You need to bind it yourself, to some provider.  I use the DBCP provided 
with Tomcat (naming-factory-dbcp.jar); the context factory is 
"org.apache.naming.java.javaURLContextFactory" (that's not a typo, the 
class name begins with a lowercase letter). Then you create your 
InitialContext, create sub contexts for each component and bind your 
object to the last context.  DBCP is an in-memory one that seems to beat 
the beta fscontext reference that Sun released.

Oracle has a class 'com.oracle.naming.J2EEContext'.  I suspect that's 
what OC4J uses.  It also seems to have 
com.evermind.server.rmi.RMIInitialContextFactory.  See if you can find 
javadocs for those.  If you're grabbing a DataSource remotely from a 
running OC4J instance, I did a quick google search and found 
http://www.oracle.com/technology/products/ias/toplink/doc/1013/MAIN/_html/cachsyn007.htm 
.. it's for TopLink, but it uses JNDI and follows the same conventions 
that your standalone OC4J (or app server) is going to use--JMS or RMI 
(corba).

HTH,
  Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [JAVA]How to get datatbase connection from lookup to datatsource name in a standalone java application

Posted by Scott Van Wart <sc...@indosoft.com>.
Caroline Jen wrote:
> Context ctx = new InitialContect();
> DataSource ds =
> (DataSource)ctx.lookup("java:com/env/jdbc/DBName");
> Connection con = ds.getConnection();
>   
Right, but that's assuming it's already bound, which is the hard part, 
and unless he's running it under OC4J, no such luck...

- Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [JAVA]How to get datatbase connection from lookup to datatsource name in a standalone java application

Posted by Caroline Jen <ji...@yahoo.com>.
Context ctx = new InitialContect();
DataSource ds =
(DataSource)ctx.lookup("java:com/env/jdbc/DBName");
Connection con = ds.getConnection();

--- Scott Van Wart <sc...@indosoft.com> wrote:

> temp temp wrote:
> > My java standalone application wants connection to
> database with lookup  to datasource name which is
> configured in the oc4j app server. 
> >   Please guide me with some ideas to achieve this.
> >   
> You need to bind it yourself, to some provider.  I
> use the DBCP provided 
> with Tomcat (naming-factory-dbcp.jar); the context
> factory is 
> "org.apache.naming.java.javaURLContextFactory"
> (that's not a typo, the 
> class name begins with a lowercase letter). Then you
> create your 
> InitialContext, create sub contexts for each
> component and bind your 
> object to the last context.  DBCP is an in-memory
> one that seems to beat 
> the beta fscontext reference that Sun released.
> 
> Oracle has a class 'com.oracle.naming.J2EEContext'. 
> I suspect that's 
> what OC4J uses.  It also seems to have 
> com.evermind.server.rmi.RMIInitialContextFactory. 
> See if you can find 
> javadocs for those.  If you're grabbing a DataSource
> remotely from a 
> running OC4J instance, I did a quick google search
> and found 
>
http://www.oracle.com/technology/products/ias/toplink/doc/1013/MAIN/_html/cachsyn007.htm
> 
> .. it's for TopLink, but it uses JNDI and follows
> the same conventions 
> that your standalone OC4J (or app server) is going
> to use--JMS or RMI 
> (corba).
> 
> HTH,
>   Scott
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org