cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get connection through datasource running on different SAP WAS

venkatesh_r
Employee
Employee
0 Kudos

My application is running on SAP WAS. I want to connect to a data source on different WAS. The below code throws NameNotFoundException. But if i connect through the data source on the same machine the code works fine.

InitialContext ctx = null;

Properties ctxProp = new Properties();

ctxProp.put(Context.INITIAL_CONTEXT_FACTORY,

"com.sap.engine.services.jndi.InitialContextFactoryImpl");

ctxProp.put(Context.PROVIDER_URL, "machine-name:50004");

ctxProp.put(Context.SECURITY_PRINCIPAL, "Administrator");

ctxProp.put(Context.SECURITY_CREDENTIALS, "*********");

try

{

ctx = new InitialContext(ctxProp); DataSource ds = (DataSource) ctx.lookup("jdbc/SAPWASDB");

Connection con = ds.getConnection();

Statement st = con.createStatement();

ResultSet rs = st.executeQuery("select * from BC_COMPVERS");

while (rs.next())

{ System.out.println("**********Values" + example);

}

}

catch (NamingException e)

{

System.err.println("**********Error" + e);

}

catch(SQLException e)

{

System.err.println("**********Error SQL" + e);

}

Accepted Solutions (1)

Accepted Solutions (1)

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi venkatesh,

Did you added other machine entries into your host file. Are you able to deploy on other m/c WAS?. If your able to deploy on other machine ideally it should work.

which line its giving "NameNotFoundException"...Is that table exist?

Regards

suresh

venkatesh_r
Employee
Employee
0 Kudos

Hi Suresh,

I didn't add the other machine's entries in the host file of my application's WAS. How do I do that?

I deployed it into the other machine where the data source exists. It works perfectly fine.

former_member192029
Active Contributor
0 Kudos

Hi

you can find the host from

C:\WINDOWS\system32\drivers\etc

just enter ipaddress and system name

Cheers

Jawahar Govindaraj

PS:Reward pts

Answers (0)