How do I connect to a Websphere Datasource with a given JNDI name?

前端 未结 6 1479
温柔的废话
温柔的废话 2020-12-07 23:15

I\'m using Websphere Portal 7.0 and creating a portlet with RAD 8.0. My portlet is trying to make a db2 connection to a remote server. I wrote a java program locally to do a

6条回答
  •  执笔经年
    2020-12-07 23:55

    For those like me, only needing information on how to connect to a (DB2) WAS Data Source from Java using JNDI lookup (Used IBM Websphere 8.5.5 & DB2 Universal JDBC Driver Provider with implementation class: com.ibm.db2.jcc.DB2ConnectionPoolDataSource):

    public DataSource getJndiDataSource() throws NamingException {
        DataSource datasource = null;
        InitialContext context = new InitialContext();
        // Tomcat/Possibly others: java:comp/env/jdbc/myDatasourceJndiName
        datasource = (DataSource) context.lookup("jdbc/myDatasourceJndiName");
        return datasource;
    }
    

提交回复
热议问题