cancel
Showing results for 
Search instead for 
Did you mean: 

How to create Portal Web Service using EJB to access Portal Database

Former Member
0 Kudos

Hi Gurus,

I'd like to write a web service providing data from internal (Oracle) database.

I've created an deployed a Dictionary Project. Since this is my first Web Service, please provide me with some tips & how-to's to get startet.

My questions in detail are:

- how do I create a EJB accessing the internal database?

- how do I create a web service using this EJB?

thanks in advance! helpful answers will be rewarded wih point, of course.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi el,

since u hav created dicionary project..

u'll have to create Ejb module projct nw..it will contain entity beans..n create a session bean hre after in ejb project..which will contain business logic..

now create java project in java perspective which will contain wrapper class for entity beans in java perspective.

nw create Enterprice Module project i.e. Ear project..in J2EE perspective.

now create webservice for session bean via right click on session bean ..->new ->Web Service..

now deploy first dictionary projct,thn .jar of ejb project n then

.Ear ..

nw test n run ur web service ...

for Ejb project creation u can go through:

[https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/1f5f3366-0401-0010-d6b0-e85a49e93a5c]

[https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/ca4a9c90-0201-0010-c389-8738cd51a88e]

hope it'll hlp u...

Regards,

Khushboo

Answers (4)

Answers (4)

Former Member
0 Kudos

And the last question, is there an other way accessing the database, for example using a jco to the MAXDB/Oracle database?

thank you!

Former Member
0 Kudos

hey guys,

thanks for your helpfull answers!

I've created a Dictionary Project, deployed it on my MAXDB.

I've written a EJB with methods for reading and writing this Database. I've used the howto [Accessing Database Table Using EJB and WebDynpro.pdf|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/70929198-0d36-2b10-04b8-84d90fa3df9c]

My Method for accessing the DB is for example:


public MyModel[] viewEntry() throws MyException { 
                ArrayList array = new ArrayList(); 
                MyModel[] myModel; 
                try { 
                        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); 
                        Connection conn = DriverManager.getConnection( 
        "jdbc:oracle:thin:@oracle_ip:oracle_port:oracle_SID", "userid", "password"); 
                        Statement stmt = conn.createStatement(); 
                        String sqlquery = "select * from Z_MY_DATABASE"; 
                        ResultSet rs = stmt.executeQuery(sqlquery); 
                        while (rs.next()) { 
                                array.add(getMyModel(rs)); 
                        } 
                        stmt.close(); 
                        conn.close(); 
                } catch (SQLException e) { 
                        e.printStackTrace(); 
                        throw new MyException(e.getMessage()); 
                } 
                myModel = new MyModel[array.size()]; 
                array.toArray(myModel); 
                return myModel; 
        } 

this example is trying to access an Oracle database using a username and passwort. is there an other way to access an Oracle DB?

second qustion is, since i'm using a local MAXDB, ho do i have to modify the code to be able to access my local DB?

Thanks in advance!

ankur_garg5
Active Contributor
0 Kudos

Hi farid,

See if you can get any help from my article:

[How to Create a Web Service using EJB Which Accesses the MS SQL Server|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/b00917dc-ead4-2910-3ebb-b0a63e49ef10]

Bye

Ankur

Former Member
0 Kudos

Hi,

First u have to create ejb project and then Web service from session bean.

For the first step,

1) you have to create table in the dictionary project

2)entity beans is used for accessing database tables i,e. dictionary tables in this case.

3)Refer the name of the table in persistent.xml

4)write your business method in session bean and refer the name of entitybean in JNDI name.

5)call the sessionbean method from the command bean and the commandbean method from the webdynpro perspective

6)create webservice from session bean.

There are some links...

Creating a J2EE-Based Car Rental Application

http://help.sap.com/saphelp_nw70/helpdata/EN/70/13353094af154a91cbe982d7dd0118/frameset.htm

EJBs in Web Dynpro Application Using Wrapper Class

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00be903b-8551-2b10-c28a-8520400c....

thanks.

Abhilasha