on 07-22-2005 12:24 PM
hello
i wish to know how to use oracle with web dynpro as database store
initially we have been using R/3 system as our store with
backend of r/3 as oracle
but now we directly want to communicate with oracle
Hi Mitesh,
Initially I had tried few ways to connect directly from WD to Oracle, but nothing worked for me. Finally I could achieve it only through ejbs & even today I stick to that. I tried out many things for connecting directly including accessing the JDBC connector service of the server, but don't know why nothing worked for me.
Anyway, I'll send you the step by step process to create the ejb & use it in your WebDynpro application to connect to the database (you might find it a bit long, but I believe I have included every step). If someone knows a better way to connect pls let us know, cos it is tiresome to write ejbs each time we need to connect.
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.
8) 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");
Hope this helps & pls do let us know if you have any further queries,
Best Regards,
Nibu.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Robin,
Thanks for your suggestion. I am not very familiar with importing JavaBean as a model. So, for the sake of achieveing the functionality, I used ejbs directly inside my WebDynpro controller, though, structurally, it may not be the best practice. I'll surely keep your advice in mind and try using Java Beans for invoking EJBs next time.
Best Regards,
Nibu.
Hi Mitesh,
Please let us know if you could access the database or if you are still facing problems. If you were able to solve your problem, kindly close the query and give the points to helpful answers :).
Regards,
Jaydeep
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mitesh,
Check this document
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/biw/g-i/how to configure ud connect on the j2ee server for jdbc access to external databases.pdf
Check this link for Oracle thin drivers
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc817.html
Message was edited by: Jaydeep Kalmankar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
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.