cancel
Showing results for 
Search instead for 
Did you mean: 

how we can do the database connection in webdynpro for java

Former Member
0 Kudos

please give me some sample examples which r using database connection.

and also give me some useful information regarding the database of the SAP

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hai,

the same problem is discussed here

Regards,

Naga

Former Member
0 Kudos

Hi shanto,

if u use oracle database do the following steps and import the class12.jar file.

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");

the above information is useful reward useful points..

Regards,

P.Manivannan

Former Member
0 Kudos

Hi Shanto

Access the below Link

Title : Accessing ABAP Functions in Web Dynpro

Link :

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/webcontent/uuid/28113de9-0601-0010-71a3-c8780... [original link is broken]

Rgds

-SS