[jboss-user] [Beginners Corner] - How to create DataSource dynamically in jboss

psivaji do-not-reply at jboss.com
Thu May 7 22:22:01 EDT 2009


Hi,

Could anyone have idea about creating datasource dynamically in jboss?

I tried to use the LocalTxDataSource, but it is getting NullPointerException when it tries to get the TranscationManager.

Here is the code for reference,

 Properties initialContextProperties = new Properties();
        initialContextProperties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
        initialContextProperties.put("java.naming.provider.url", "jnp://localhost:1099/");
        
        
        LocalTxDataSource localDataSource = new LocalTxDataSource();
        CachedConnectionManagerReference ccmr = new CachedConnectionManagerReference();
  
        
        localDataSource.setInitialContextProperties(initialContextProperties);
        localDataSource.setConnectionURL(connectionURL);
        localDataSource.setDriverClass(driverClass);
        localDataSource.setUserName(userName);
        localDataSource.setPassword(password);
        localDataSource.setMinSize(minSize);
        localDataSource.setMaxSize(maxSize);
        localDataSource.setJndiName(dsName);
        localDataSource.setNewConnectionSQL(query);
        localDataSource.setValidConnectionCheckerClassName("org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker");
        localDataSource.setCheckValidConnectionSQL(query);
        localDataSource.setTransactionIsolation("TRANSACTION_READ_COMMITTED");
        
        
        try {
            InitialContext ctx = new InitialContext(initialContextProperties);
            localDataSource.setCachedConnectionManager(ccmr);
            //localDataSource.bindConnectionFactory();
            localDataSource.start();
 DataSource ds = (DataSource)ctx.lookup(dsName);
             logger.debug("DSConfigureScheduler::ds: "+ds);
             con = ds.getConnection();  //It fails here

Thanks,
Pugazhenthi.S


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4229596#4229596

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4229596



More information about the jboss-user mailing list