cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Web Dynpro work with Database?

Former Member
0 Kudos

Hi Experts,

I intend to create a custom Web Dynpro Application to work with custom database. I wondering what are the ways that I can create the database and how the database can be accessible by the application? : )

Best Regards

Rayden

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos
Former Member
0 Kudos

Hi Anilkumar & Suresh,

Thanks for the info. Most of the info is connecting to Oracle. Is there any ways like use own SAP function / Database?

Best Regards,

Rayden

Answers (4)

Answers (4)

siddharth_jain
Active Contributor
0 Kudos

Hi Rayden,

for connecting WD application with SAP max db you can follow these steps:-

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/<aliasname>.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 max DB.

Please Award points if u find this post Usefull.

Regards,

Siddharth Jain.

Former Member
0 Kudos

Hi Siddharth Jain,

That was useful. Is there any elearning / tutorial material on this?

Best Regards,

Rayden

Former Member