cancel
Showing results for 
Search instead for 
Did you mean: 

How to query a sql database table from webdynpro?

Former Member
0 Kudos

Hi All,

Can someone tell me the steps involved in accessing a sql server database table and retrieving the record set from a webdynpro application.

Thanks in advance.

Best regards,

Divya

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Divya,

here is a code sample that may help you (SAPTT3DB is the name of the DataSource. In my case,SAP<SID>DB. You can find this in the Visual Administrator):

ResultSet rs;

boolean found=false;

try {

InitialContext ctx = new InitialContext();

javax.sql.DataSource ds =

(javax.sql.DataSource) ctx.lookup("jdbc/SAPTT3DB");

java.sql.Connection con = ds.getConnection();

java.sql.Statement stmt = con.createStatement();

rs = stmt.executeQuery("SELECT * FROM DEMO_FP where NUMERO="+num);

while (rs.next()){

found=true;

wdContext.currentFichePrixElement().setCodeAch(rs.getString("CODE_ACH"));

[...]

}

con.close();

}

catch(Exception e){

msgMgr.reportException(e.getMessage(),true);

}

Best Regards,

Julien

Former Member
0 Kudos

Hi Divya,

The following link has step by step description which will help you

Hope this helps you

Regards

Rohit

Former Member
0 Kudos

Hi All,

Thanks for all the info. I just wanted to know as to how I could bind the values returned in the record set to a table UI element.

This is described in case of BAPIs in the tutorial would be of great help if someone guided as to how this could be done in case of sql query record sets.

Thanks in advance.

Best regards,

Divya Rao

Former Member
0 Kudos

Hi Julien,

This is where am stuck I get the record set but when I assign it to the UI element of type table it does not display it right. I have created a conext of type node attribute having node values.Code is enclosed as below:

while (rs.next()){

wdContext.nodeData().cuurentcontextElement.setDataField1(rs.getString("Test1"));

wdContext.nodeData().cuurentcontextElement.setDataField2(rs.getString("Test2"));

}

The data is not bound to the UI table. Can you suggest another way to do so please.

Thanks in advance.

Best regards,

Divya

Former Member
0 Kudos

Hi Divya,

Create a node with the required attributes.

In the left hand side where the project structure is being shown right click on the view and choose "Apply Template" .

Choose the "table" and then the attributes you want to display in table

Write this code in the implementation

IPrivate<view name>.I<node name>Element element;

While(rs.next())

{

element = wdContext.node<node name>.create<node name>element();

element.setDataField1(rs.getString("Test1"));

element.setDataField2(rs.getString("Test2"));

wdContext.node<node name>.addelement(element);

}

Hope this helps you

Regards

Rohit

former_member182372
Active Contributor
0 Kudos