cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing and Retrieving data from SQLServer from Webdynpro

Former Member
0 Kudos

Hello,

I've been going through posts in here to try to find out howto access and retrieve data from a SQLServer database.

We are making a Webdynpro app that is using access to both SAP and SQLServer data and I need to know howto create a connection and retrieving data from SQLServer with a EJB.

Can someone please show me a complete example on howto do this with a EJB? or is there a better/simpler way to do it that with an EJB?.

I'm a beginner at EJB so please bear with me...

I've looked at some examples in here but I can't figure out where (in files) to put the code snippets I've found.

Thank you

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

This is a simple way to make a connection to a DB (in

this case i have used the DB which is used by the WAS).

javax.naming.InitialContext ctx = new javax.naming.InitialContext();
javax.sql.DataSource ds =(javax.sql.DataSource)
 ctx.lookup("jdbc/<DATABASE ALIAS NAME>");

java.sql.Connection conn = ds.getConnection();
java.sql.Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("<your query here>");

Read the retrieved values from ResultSet and store it in bean.

Thanks

Senthil

P.S: Reward Points for useful answers

Former Member
0 Kudos

Thank you for your answers!

I guess I should put this code in the Bean, right?

Can I just try the most simple way and declare methods in home and remote and put the actual working code in the Bean?

Regards

Former Member
0 Kudos

Hi,

Check out this link as well.

http://help.sap.com/saphelp_nw04/helpdata/en/43/2eafd8d2f30d24e10000000a1553f7/frameset.htm

Thanks

Senthil

P.S: Reward Points for useful answers

Former Member
0 Kudos

Thank you all for your help, much appreciated!

Regards

Answers (1)

Answers (1)

guru_subramanianb
Active Contributor
0 Kudos

Hi Peter,

Refer the below link.It will be helpful surely.

http://help.sap.com/saphelp_nw04/helpdata/en/f8/bdfe80d9a3b048a5fb32a7d149774e/frameset.htm

regards,

Guru