on 08-19-2007 9:59 PM
Hi All,
I have to create an sample application where i have to access the MaxDB Table directly in Webdynpro.
Starting I just created normal java application in NWDS to access the table and it was successful, but when i copied the same DB access code in WdInit method of component controller it doesnt work....
Can u tell me how can i progress further to achieve the desired result using Webdynpro and show table values in Webdynpro View.
HI RIcky,
It's not recommeneded to write database operation direcrly in web dynpro. i Suggest u to keep these statements in EJB.
accessing table data:
1.You have to create database alias for that DataSource.
2.if u are accessing ur data from ur WAS DataBase,you can create your DataBase alias by specfying entry in configuration file(XML) of EJB or you can use exsintg DataSource alias
3.once u have data Source alias u can use following JDBC code for perfroing databse operations.
IniitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/<aliasname>");
Connection con = ds.getConnection();
Statemnet stmt = con.createStament();
ResultSet rs = stamt.eqecuteQuery(sql stament);
u can also keep above dorectly in webdynpro but its better to follow MVC paradigm
hopw this helps
With Regards
Naidu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your replies... I will work on your suggestions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ricky,
using EJB and access into database table directly, please do the following steps,
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 its 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 projects 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");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
What problem you get. I think you might be getting problem in loading the jdbc driver.
Any way, accessing tables via JDBC directly in UI code is not good. Use EJBs for that.
See this tutorial:
In Web Dynpro the backend data should be accessed via "Models". Models are interface that enables UI to get/set the data from backend source. Hence use models for this.
Regards,
Ashwani Kr Sharma
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.