cancel
Showing results for 
Search instead for 
Did you mean: 

Connection to Databases

Former Member
0 Kudos

In which way can I connect a Database from an WebDynPro - Project? Is there any technology like binding to a RFC - BAPI ? I cnan't find any tutorial here.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

I am unable to get this working inside my WD Application. I'm calling the server like so:

InitialContext ctx = new InitialContext();

DataSource ds = (DataSource)ctx.lookup("jdbc/SRVERNAME");

where SRVERNAME is the ds name in before mentioned virtual admin location. I receive the Object Not Found in lookup of SRVERNAME.

The code is currently located in a method added to one of my views. Any suggestions?

Regards

Former Member
0 Kudos

Hi Brent,

you have to restart the server before this works.

Hope that helps.

Regards

Stefan

Former Member
0 Kudos

Hi,*

I was very glad to see this discussion, I think this is a really important point of the WD technology.

Never the less I have a little bit different point of view on this issue. You are talking about EJB as a beans to distribute some common application logic over differnt application, but it seems to me that SAP wants you to use WD components instead. This is a reason, I think, for such a tight coupling among model and component, the model is not redistributable but the component which envelope the model (Adaptive RFC model) is. So just instead of enveloping logic in EJB, envelope it in WD component and use from others. That's the way I think they want us to work and in general I have no reason to go back to EJB and to work hard , doing Jco stuff myself.

P.S. do you know the reason for removing the EJB kind of model form SP5?

Best regards,

Victor

Former Member
0 Kudos

Hi Victor,

i'm glad to see more interested people participating in this discussion.

But using the (really great) Web Dynpro component model is not the solution here.

Web Dynpro is very well suitable to manage the presentation layer of a business application, but, especially in conjunction with Dynamic RFC models usage, starts handling of security and transaction management issues, which should <b>not at all</b> be part of this layer.

You as the presentation logic developer must decide, when to call BAPI_TRANSACTION_COMMIT for example!! Do you know all other DRFC model users and the changes, they might already have done before you are "called" in any possible combination with the component you're currently implementing?

I don't think so and the fact is, you <b>shouldn't have to</b> think about this, because that's exactly what is handled by the transaction management of the J2EE engine normally (at least in case of container managed demarcation).

And of course you don't want to do those nasty JCo stuff by yourself inside the EJB. But you won't have to do so, since you even won't know, that you are using a SAP system as the EIS, which provides the business logic.

Best regards

Stefan

htammen
Active Contributor
0 Kudos

Hi Christof,

I would suggest to write an EJB (e.g. stateless session bean) and generate a Web Service for this.

Then you can use this Web Service to generate a Web Dynpro model.

An example is enclosed in the "car rental tutorial".

Another way to get data from a database is using JDO. There is also a tutorial or description available for this (search the SDN).

You can of course connect to a database from a component or view controller via JDBC or SQLJ but you shouldn´t use this approach because then there is no separation of presentation layer and business logic layer.

Regards

Helmut

Former Member
0 Kudos

Hi Helmut,

by the way, isn't the coupling of Web Dynpro applications and the backend at least in case of using Adaptive RFC models much too tight?

Wouldn't it be better to implement facades (these might be represented by Virtual Web Service interfaces, but i'm wondering about the performance then), wrap the JCO calls in the transactional SAPJRA environment using EJBs for the backend access?

We're losing things like automatic field- and column labeling then, but i'm thinking about the scenario transferring a large number of WD apps which are using the R/3 backend to another business layer...

Maybe i'm a little bit too accurate there, just grabbing for another opinion

Best regards

Stefan

htammen
Active Contributor
0 Kudos

Hi Stefan,

I agree with you. I also don´t really like Adaptive RFC. The EJB approach you mentioned is the better solution I think.

In a customer project we are going this way. But at the moment there is the the drawback that you have to communicate with your EJBs via Web Services which are stateless and require another layer. SAP wrote an extension to use stateful Web Services but this doesn´t work yet.

I asked different people at SAP during the last weeks if and when direct EJB support with model generation will come but it doesn´t seem that we can use it in Netweaver 04.

I think this is a very important feature because it could bring standard J2EE programmers to Web Dynpro. People at SAP don´t see it that way. They seem to be R/3 driven which might be correct for "Web Dynpro for ABAP".

J2EE programmers don´t want to connect to a R/3 system directly just to get the functionality of this system. They want to work with different layers which can be exchanged easily, right? J2EE patterns is the buzzword in this environment.

Hopefully Shai Agassi reads this thread

Regards

Helmut

Former Member
0 Kudos

Hi Helmut,

thank you very much for this statement indeed, since it relieves me from thinking i'm the only one (outside SAP) having this doubts! I discussed this months ago with somebody from SAP also and he agreed, but as far as i know, he's "coming from the J2EE world", so this is not really a surprise (unfortunately, it wasn't Shai Agassi ).

There's definitely a lack of layer abstraction in case of accessing R/3 systems via WD. This might be partially the result of assuming that customers will always use ABAP for the business logic, leaving the presentation layer to Java/J2EE (at least if WD for ABAP is released).

Best regards

Stefan

Former Member
0 Kudos

Hello,

for a small aplication, I am willing to give up the separation of presentation and business logic and use JDBC in WebDynpro. My problem is, how do I get/specify a dataSource in WebDynpro.

I want to do like this:

InitialContext ctx = new InitialContext();

DataSource dataSource = (DataSource) ctx.lookup("java:comp/env/SAPC11DB");

conn = dataSource.getConnection();

but at runtime the lookup fails. Well, of course, because I do not know where to specify it.

thanx

Walter

Former Member
0 Kudos

Hi Walter,

you can add/manage JDBC DataSources using the Visual Admin. It's easy if you are using the default Max/SAPDb for this, otherwise you'll have to add the vendor specific driver first.

Please have a look at: ServerNode->Services->JDBC Connector.

Hope that helps.

Regards

Stefan

PS: Better think twice before giving up separation )

PSS: What i've forgotten to mention: The lookup of jdbc datasources can be done using the JNDI-directory alias "jdbc" so

DataSource ds = (DataSource) initialContext.lookup("jdbc/YourDSName");
Connection connection = datasource.getConnection();

should be sufficient.

Message was edited by: Stefan Klensch

Former Member
0 Kudos

Hi Stefan,

there, I can add aliases, but when I add Alias "WD_PERSISTENCE_EXAMPLE" the Deployer is set to "SAPC11DB DataSource". After restarting my J2EE engine, in

dataSource = ctx.lookup("java:comp/env/WD_PERSISTENCE_EXAMPLE");

I still get the error "path to object does not exist at java:comp".

bad luck (for me)

Walter

Former Member
0 Kudos

Hi Walter,

did you try the "jdbc/WD_PERSISTENCE_EXAMPLE" version? I added the lookup to my previous post, so you might not have read it.

Best regards

Stefan

Former Member
0 Kudos

perfect, thanks

Walter