cancel
Showing results for 
Search instead for 
Did you mean: 

getting results from java dictionary table to WD appl

Former Member
0 Kudos

Hi all.

I created One java dictionary table. Now i want to get results from that table to Web Dynpro application.

Pl anyone help me.

with regards,

Gobinath.R

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

u can do this by using Ejb.

For the first step,

1) you have to create table in the dictionary project

2) create EJB (by j2ee prespective) here 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

There are some links...

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....

Using EJBs in Web Dynpro Applications

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

Accessing database table using EJB and web dynpro

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/70929198-0d36-2b10-04b8-84d90fa3...

Creating a J2EE-Based Car Rental Application

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

Regards.

Abhilasha

siddharth_jain
Active Contributor
0 Kudos

Hi ,

You should follow the SAP Recommended way to Work with DATA base in WD ,Which is mentioned in the Tutorial link

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c0b53558-6df6-2910-cfbf-a63316bb...

Also you can follow a brief step wise step procedure you can use this as workaround or mold it with the Abobe tutorial Methodology, This deals with SAP Web AS DB:--

1:-first create a web module project.

2:-create enterprise application module project.when the project is created in the j2ee project explorer pane right click on project name a context menu will come up select the first option META_INF/data -source-aliases.

3:-give any valid name to your datasource alias. and save it.

4:-and enter the name of your datasource alias name in web.xml of your web moudule .open web.xml and click on resoure tab, add new resource entry like this :--jdbc/.and save it.

5.build and create web archive.

6.add the web module in your enterprise application project which you have already created.

7.build and create enterprise archive . and deploy it on WAS. make sure that it is successfully deployed.

8. now the next step is creation of database create a New dictionary project from the new submenu.

9.select database table from the hierarchy and click create new tables from the context menu.Give a name and finish. define your fields and save it.when its done click on the table name u have just created , choose generate ddl script from the context menu Select max db and after that deploy it on the server.

10.now the next step is establish a connection here datasource alias will come into the picture.

11. simplest procedure is create a web dynpro project and design your screen according the tables and write all the methods for database connectivity,retrieval and modification in componant controller .and access it from your views.

10.here is the code for establishing connection.

public java.sql.Connection getConnection( )

{

//@@begin getConnection()

try {

InitialContext init = new InitialContext();

Object obj = (Object) init.lookup("jdbc/<datasourcename>");

DataSource ds =

(DataSource) PortableRemoteObject.narrow(obj, DataSource.class);

con = ds.getConnection();

return con;

} catch (Exception e) {

System.out.println("Error in connection " + e.getMessage());

return null;

}

//@@end

}

12.for inserting updating and selecting u can write similar methods.

public java.sql.ResultSet selectEmpdata( java.lang.String Field1, java.sql.Connection con1 )

{

//@@begin selectEmpdata()

ResultSet rs = null;

try {

PreparedStatement st1 =

con1.prepareStatement(

"select field1,field2 from table_name where field1='"value"'");

rs = st1.executeQuery();

// while (rs.next())

// {

// wdComponentAPI.getMessageManager().reportSuccess("col1"+rs.getString(1));

// wdComponentAPI.getMessageManager().reportSuccess("col2"+rs.getString(2));

// wdComponentAPI.getMessageManager().reportSuccess("col3"+rs.getString(3));

// }

} catch (Exception e) {

wdComponentAPI.getMessageManager().reportException("component"+e.getMessage(),true);

return null;

}

return rs;

//@@end

}

so these are the complete steps for developing a sample database application with SAP DB.

Regards,

Siddharth