on 06-10-2008 2:00 PM
Hello Experts,
I'm trying to pass a database connection from my portal component to a web module.
Hashtable env = new Hashtable();
env.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.sap.engine.services.jndi.InitialContextFactoryImpl");
ctx.bind("java:comp/ourDBConnection", connection);
Afterwards I destroy the context and open it again for debugging purposes.
Then, for debugging I have the following code:
NamingEnumeration ne = ctx.list("java:comp");
while (ne.hasMore()) {
NameClassPair ncp = (NameClassPair) ne.nextElement();
response.write(ncp.getName() + "<br>");
}
When I use this debugging code inside the portal component, it displays the following entries
ORB
ourDBConnection
UserTransaction
env
But inside the web module I only get the following entries:
ORB
UserTransaction
env
That is, the object that I added is not listed.
What is wrong about how I use JNDI? Why does the connection object not appear in the context when I call it from the web module?
Looking forward to your replies, sincerely,
Florian
Hi,
If you want to connect to SAP R3 from Java you can try out the following code. This code i have already implemented and it is running.
// *Obtain the initial JNDI context*
Context ctx = new InitialContext();
// *Perform JNDI lookup to obtain connection factory*
IConnectionFactory connectionFactory = (IConnectionFactory) ctx.lookup ("deployedAdapters/SAPFactory/shareable/SAPFactory");
//*Note that from SP3 onwards the lookup string would be "deployedAdapters/SAPFactory/shareable/SAPFactory or EISConnections/SAPFactory*"
IConnectionSpec spec = connectionFactory.getConnectionSpec();
spec.setPropertyValue("client", clientNo);
spec.setPropertyValue("UserName", userName); //uppercaps
spec.setPropertyValue("Password",passwd);
spec.setPropertyValue("Language", lang);
spec.setPropertyValue("logonmethod", logOnMethod);
spec.setPropertyValue("SystemType", systemType);
// note that property *SystemType* is a mandatory task.. in my case Connection was not established in the absence of this property
spec.setPropertyValue("ashost",shost);//ip address
spec.setPropertyValue("sysnr", sysnr);
IConnection client = connectionFactory.getConnectionEx(spec);
Try this out and if helpful please do reward with points.
Thanks
Ritushree
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.