在Jboss 4.2中从DataSource获取连接时出现异常

时间:2014-02-25 13:23:39

标签: jboss jndi

我无法从Jboss4.2中的Datasource获得连接,因为init.lookup(" JNDINAME")方法和$ Proxy1作为连接结果而抛出$ Proxy0。请在下面找到我用来从Datasource获取连接的方法。

public Connection getConnectionForBatchJob(){
        Connection con = null;

        DataSource ds = null;
        try {
                MessageResources resource = new PropertyMessageResources(null, "common.resources_en");
                Properties properties = new Properties();

                properties.setProperty(resource.getMessage("nightly.batchjob.JNDIintialFactoryKey"),
                        resource.getMessage("nightly.batchjob.JNDIintialFactoryValue"));

                properties.setProperty(resource.getMessage("nightly.batchjob.JNDINamingProviderUrlKey"),
                        resource.getMessage("nightly.batchjob.JNDINamingProviderUrlValue"));

                properties.setProperty(resource.getMessage("nightly.batchjob.JNDInamingFactoryUrlKey"),
                        resource.getMessage("nightly.batchjob.JNDInamingFactoryUrlValue"));

                Context init = new InitialContext(properties);

                Object o=init.lookup(resource.getMessage("consts.jndi.lookup.name"));

                System.out.println("The Object of returned class:::::"+o.getClass().getName());

                ds = (DataSource)o ;

                System.out.println("DS:::"+ds.getClass().getName());

            if (ds == null){
                log.error("Datasource is Null ........");
                return null;
            }

            con = ds.getConnection();

            System.out.println("Conn:::"+con.getClass().getName());

            if (con == null){
                log.warn("GOT the Null COnnection .............................");
            }
        } catch (Exception e) {
            log.error("DatabaseActivityManagerImpl:getConnectionForBatchJob: Closing Connection :: "+ e.getMessage());
            e.printStackTrace();
        }  finally {
            ds = null;
        }
        return con;

    }

OutPut:

The Object of returned class:::::$Proxy0
DS:::$Proxy0
Conn:::$Proxy1

Below are the properties I have used:

nightly.batchjob.JNDIintialFactoryKey=java.naming.factory.initial
nightly.batchjob.JNDIintialFactoryValue=org.jnp.interfaces.NamingContextFactory
nightly.batchjob.JNDINamingProviderUrlKey=java.naming.provider.url
nightly.batchjob.JNDINamingProviderUrlValue=jnp://localhost:1099
nightly.batchjob.JNDInamingFactoryUrlKey=java.naming.factory.url.pkgs`enter code here`
nightly.batchjob.JNDInamingFactoryUrlValue=org.jboss.naming
consts.jndi.lookup.name=jdbc/ESPMART

Because of this issue I am getting following ClassCastException

java.lang.ClassCastException: $Proxy4

0 个答案:

没有答案