简体   繁体   中英

javax.naming.NameNotFoundException: env/jdbc/DataSource on JBOSS with SQL Server

The JNDI name in my domain.xml is

The Context.lookup has been defined as follows:

dsName = "java:comp/env";

Context ctx = (Context) new javax.naming.InitialContext();

Context envCtx = (Context)ctx.lookup(dsName);

DataSource ds = (DataSource)envCtx.lookup("jdbc/DataSource");

conn = ds.getConnection();

I'm getting the following exception when connected to SQLserver with the following configuration where as it is working fine with Oracle.The lookup name somehow is not validated properly and connection object is getting null.

javax.naming.NameNotFoundException: env/jdbc/DataSource

ERROR [stderr] (ServerService Thread Pool -- 78) at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:104)

ERROR [stderr] (ServerService Thread Pool -- 78) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197) java.lang.NullPointerException

Even Tried with something like

DataSource ds = (DataSource)envCtx.lookup("java:comp/env/jdbc/DataSource");

Could anyone suggest on this.

Thanks

Check the logs and/or the JNDI tree in the administration console.

Try these:

"java:DataSource"
"java:jboss/datasources/DataSource"

If not, please paste here the data source config section in the config file (eg standalone.xml)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM