> you can use JNDI to get a DataSource (if you use tomcat see tomcat > documentation in order to set the datasource). > Here an example code to use inside the singleton object: > > //Get DB from JNDI > try { > Context initCtx = new InitialContext(); > Context envCtx = (Context) initCtx.lookup("java:comp/env"); > DataSource dataSource = (DataSource) > envCtx.lookup("jdbc/DatabaseSource"); > > } catch ( NamingException e ) { > //Handle Source Code Exception > } >
This is a nice solution, but I would like to use the DataSource configuration in struts-config.xml. I noticed that there is the "ConfigHelper.getDataSource()" method to get the default data source, but I want to use a DataSource that I mapped with a key. By the way, the solution above is not too tied to Tomcat? What if I want to distribute my application? Do I have to configure Tomcat on the other machine? Ciao Antonio Petrelli > > > > -----Messaggio originale----- > Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Inviato: marted́ 21 settembre 2004 11.11 > A: [EMAIL PROTECTED] > Oggetto: Assigning a DataSource to a Business Delegate on startup > > > Hello there, > is there a way I can assign a DataSource to a singleton object (i.e. a > Business Delegate) on startup? I know there is the "getDataSource" > protected method in Action, but I have to pass the DataSource itself on > each call of the delegate, or I have to check whether it has been > already passed or not. Maybe it could be done with a plugin. In this > case, is there already a package that I could use? And if not, how can I > access to a DataSource outside the Action class? Thanks in advance Ciao > Antonio Petrelli > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]