现在的位置: 首页 > 综合 > 正文

jboss 获取数据源

2014年12月03日 ⁄ 综合 ⁄ 共 643字 ⁄ 字号 评论关闭

Hashtable parms = new Hashtable();
parms.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.NamingContextFactory.class.getName());
parms.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");
// Refer to JBOSS recommendation, do not use "localhost" when clustering
// It gets the JBoss Server Startup Parameter "-b"
//parms.put(Context.PROVIDER_URL, "localhost:1099");
String host = System.getProperty("jboss.bind.address");
host = (host!=null && host.length() > 0)?host:"localhost";
parms.put(Context.PROVIDER_URL, host+":1099");

Context context = new InitialContext(parms);
DataSource ds= (DataSource)javax.rmi.PortableRemoteObject.narrow(context.lookup("jdbc/ds"), javax.sql.DataSource.class);

抱歉!评论已关闭.