JNDI connection works on tomcat but does not work on WebSphere

0

Good morning,

I connect to my database via JNDI connection. To this day I ran my application on my local machine on a Tomcat application server:

Context.xml

<Resource
         url="jdbc:sqlserver://1.1.1.1:1434;databaseName=meuDB"
         driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
         username="admin"
         password="admin"
         maxWait="10000"
         maxIdle="30"
         maxActive="100"
         type="javax.sql.DataSource"
         auth="Container"
         name="jdbc/dataquality_sqlServer"/>

Web.xml

<resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/dataquality_sqlServer</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

Connection class - ConnectionManager

public void iniciar() {

        Context envContext = null;
        DataSource dataSource = null;


        try {
            Context ctx = new InitialContext();
            dataSource = (DataSource) ctx.lookup("java:/comp/env/jdbc/dataquality_sqlServer");
            System.out.println("conectado com sucesso!JNDI");
            conexao = dataSource.getConnection();
            conexao.setAutoCommit(false);

        } catch (Exception e){
            e.printStackTrace();
            //return null;
        }finally {
            if(envContext != null){
                try{
                   envContext.close();
                } catch (NamingException e){
                    System.out.println();
                    e.printStackTrace();
                }
            }
        }
    }

This all works normally on my local machine in Tomcat, but when migrating to the WebSphere server, it starts to fail.

Log

[10/22/18 9:50:10:469 BRST] 000001c0 SystemErr     R javax.naming.NameNotFoundException: Name  not found in context "java:".
[10/22/18 9:50:10:469 BRST] 000001c0 SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1970)
[10/22/18 9:50:10:469 BRST] 000001c0 SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.retrieveBinding(NameSpace.java:1377)
[10/22/18 9:50:10:470 BRST] 000001c0 SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1220)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr     R    at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1142)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr     R    at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1436)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr     R    at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:477)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr     R    at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:485)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr     R    at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:370)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr     R    at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr     R    at javax.naming.InitialContext.lookup(InitialContext.java:428)
[10/22/18 9:50:10:472 BRST] 000001c0 SystemErr     R    at DAO.GerenciadorDeConexao.iniciar(GerenciadorDeConexao.java:30)

The 30 line in Connection Manager is as follows:

dataSource = (DataSource) ctx.lookup("java:/comp/env/jdbc/dataquality_sqlServer");

Websphere:

    
asked by anonymous 23.10.2018 / 14:05

0 answers