Hi:
This is what I do for testing. I made a class for creating a jndi directory and I create this in my main, then I can get a datasource from the jndi directory just like I do it when running tomcat.

jndi.properties
java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory
java.naming.factory.url.pkgs=org.apache.naming
java.naming.provider.url=java

public static void create_JNDI(){
//jndi.properties must be on the classpath to make the initial context //you can either add the environment manually vida infra or have a jndi.properties file
/*              Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.naming.java.javaURLContextFactory");
           env.put(Context.URL_PKG_PREFIXES,"org.apache.naming");
           env.put(Context.PROVIDER_URL,"java");
           Context initial = new InitialContext(env);*/
               try {
                       Context initial = new InitialContext();
                       Context javaCompEnv = initial.
createSubcontext(new CompositeName().add("java:")).
                               createSubcontext("comp").
                               createSubcontext("env");
                       Context jdbc = javaCompEnv.createSubcontext("jdbc");

                       DataSource dataSource = setupDataSource();
                       jdbc.bind("mydatasourcet", dataSource);
               } catch (NamingException e) {
                       throw new RuntimeException(e);
               }

       }

private static DataSource setupDataSource() {
// BasicDataSource is from DBCP commons or it is repackaged by tomcat as //org.apache.tomcat.dbcp.dbcp.BasicDataSource BasicDataSource ds = new BasicDataSource(); //this is from DBCP commons
       ds.setDriverClassName("yourdrivergoeshere");
       ds.setUsername("user");
       ds.setPassword("pwxxx");
       ds.setUrl("yourjdbcurlgoeshere");
       ds.setMaxActive(4);
       ds.setMaxIdle(4);
       return ds;
   }
mas

Eric P wrote:
Hi,

(Tomcat newb alert)

I've got a simple database servlet application that has a few model classes on the back end.

I have the model classes pretty well genericized so that they could (almost) be utilized outside of Tomcat by another app, but they do utilize the Tomcat data sources I've set up (via an InitialContext data source lookup). So this makes it impossible (?) to execute the model classes outside of Tomcat.

Does anyone have any suggestions about how they would approach this problem so that they could debug and/or utilize these model classes that rely on database access?

Thanks for reading.  I'm open to any/all ideas.
Eric P.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to