cancel
Showing results for 
Search instead for 
Did you mean: 

Webdynpro and Oracle

former_member1279004
Participant
0 Kudos

Hi,

I am evaluating the Webdynpro client for development. Is it possible to use Webdynpro to connect/retrieve data from an Oracle database.

Thank you.

NAC

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi NAC,

yes it is very well possible to fetch data from any database in WebDynpro.

For connecting to Oracle, either you can use the normal JDBC connectivty code directly which is given below :

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@Oracle_server_ip:Oracle port:SID of the Database","user_name","password");

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("your query");

In case you want to fetch data through ejbs, these are the steps to be followed :

1) Open the J2EE perspective

2) Create an EJB Module project

3) Right click on ejbModule, create a new EJB (select your EJB type)

4) While creating the ejb itself, you can add business methods by clicking ‘Next’ in the UI. Another option is after creating the ejb, write the method in the bean, then select the method from ejb-jar.xml -> <bean name> ->method. Right click and select ‘propogate to local & remote’.

5) Double click on ejb-j2ee-engine.xml. select your bean and specify a Jndi name for eg: “MyJndi”.

6) Right click on the EJB project and add ‘classes12.zip’ file (provided by Oracle) to it’s build path. (under libraries tab). Also check the same file under ‘Order & Export’.

7) Create an Enterprise Application project.

😎 Right click on the EJB module project and select add to EAR project, then select the created EAR project.

9) Right click on the EJB project, select ‘Build EJB Archive’

10) Right click on the EAR project, select ‘Build Application Archive’

11) Open the WebDynpro perspective, open a new project, right click on the project ->properties. Do the following configurations :-

• Java Build path - select the EJB project from ‘projects’ , check the selected project under ‘Order & Export’

• Project references – select the EAR project

• WebDynpro references – select ‘sharing references’ tab, click add & make an entry as : <vendor>/<EAR project name without .ear extension>

You can find the vendor name under ‘application-j2ee-engine.xml’ file of the EAR project. By default it is ‘sap.com’. So if my EAR project’s name is ABC, my entry would look like ‘sap.com/ABC’

12) Now the configurations are over and the EJB can be invoked by writing the client code inside the webdynpro component. Like:

InitialContext context = new InitialContext();

Object obj = context.lookup("MyJndi");

MyEJBHome home = MyEJBHome)PortableRemoteObject.narrow(obj,MyEJBHome.class);

MyEJB mybean = home.create();

int a = 0;

a= mybean.add(10,15);

wdContext.currentContextElement().setSum(a);

where ‘MyEJB’ is my EJB name and ‘MyJndi’ is my JNDI name

To connect to Oracle , you can write the usual Java code (given below) as a business methos of the ejb (similar to add() method in the example). And access it like mybean.<businessMethodName>().

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@Oracle_server_ip:Oracle port:SID of the Database","user_name","password");

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("your query");

Hope this helps,

Best Regards,

Nibu.

Answers (0)