cancel
Showing results for 
Search instead for 
Did you mean: 

Ejb in web dynpro for java

Former Member
0 Kudos

Hi,

i have a scenario in which I need to insert as well as retrive data from a dictionary table on SAP DB.

can anyone provide me step by step procedure or code?

Plz dont give the links of bonus application,car rental application and phonebook application.

Thanks in Advance.

Accepted Solutions (0)

Answers (2)

Answers (2)

siddharth_jain
Active Contributor
0 Kudos

Hi Abhilasha,

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

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.

Please Award points if u find this post Usefull.

Regards,

Siddharth Jain.

Former Member
0 Kudos

Hi ,

inserting data into database ..

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>

<%

String firstname = request.getParameter("FIRSTNAME");

String lastname = request.getParameter("LASTNAME");

String address1 = request.getParameter("ADDRESS");

String address2 = request.getParameter("ADDRESS2");

String address3 = request.getParameter("ADDRESS3");

String city = request.getParameter("CITY");

String province = request.getParameter("PROVINCE");

String memo = request.getParameter("MEMO");

Class.forName("com.mysql.jdbc.Driver");

Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/funeral", "root", "abc123");

ResultSet rs = null;

Statement statement = connection.createStatement();

String sql = ("INSERT INTO memory VALUES ('" + firstname + "','" + lastname + "','" + address1 + "','"+ address2 "','" address3 "','" city "','" postalcode "','" province "','" memo +"') ");

statement.executeUpdate(sql);

rs.close();

connection.close();

%>----


for retrieving data from database ...

i think first we have to

import java.sql.*;

public class SelectApp {

public static void main(String args[]) {

String url = "jdbc:msql://athens.imaginary.com:4333/db_web";

try {

Class.forName("imaginary.sql.iMsqlDriver");

}

catch( Exception e ) {

System.out.println("Failed to load mSQL driver.");

return;

}

try {

Connection con = DriverManager.getConnection(url, "borg", "");

Statement select = con.createStatement();

ResultSet result = select.executeQuery

("SELECT key, val FROM t_test");

System.out.println("Got results:");

while(result.next()) { // process results one row at a time

int key = result.getInt(1);

String val = result.getString(2);

System.out.println("key = " + key);

System.out.println("val = " + val);

}

select.close();

con.close();

}

catch( Exception e ) {

e.printStackTrace();

}

}

}

Try the above code ...... it will okay i think soo ..

Regards ,

Venkat P