cancel
Showing results for 
Search instead for 
Did you mean: 

Basic TableUI element to Retrieve Data from DB in WEbDynPro For Java

Former Member
0 Kudos

Hi Experts,

I am new to WebDynPro for java.Can any body please help me out from this issue.

I am trying to display records from DataBase by Using Table UI element.

DBTable Contains 10 rows.

I have created a Node and Attributes(for every column) .

I am using JDBC code to retrieve data from database and assigning to Attributes.

But in Table UIElement its displaying only last record from database as first row in UIElement.

Its over writing previous rows.

Can any body please help me the correct procedure to retrieve data from DataBase.

Thanks and Regards,

Shashikiran.B

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hai shashi,

There is no need to create seperate nodes for each column.All you have to do is create a node(table) and create as many attributes with respect to columns.For instance if you have 3 columns in the table create 3 attributes under that node(table) say attribute a,b,c.Now go to the properties of table and in the datasource property of table choose the table node from the context so that the data is binded.Now just follow the following code

for(int i=0;i<table in db.size();i++)

{

wdcontext.nodetable.seta(field in the database table to be set here)

wdcontext.nodetable.setb()

..

}

Try this ...Any issues let me know..

Thanks n Regards

Sharanya.R

Former Member
0 Kudos

Hi Sharanya,

I tried same what u have specified . and i write following code to set context attributes values with dbcolumn values.

following is my code to set context attributs.

ResultSet rs = st.executeQuery("Select * from office ");

while(rs.next()){

wdContext.nodeEmpDetails().currentEmpDetailsElement().setSNo(rs.getString(1));

wdContext.nodeEmpDetails().currentEmpDetailsElement().setName(rs.getString(2));

wdContext.nodeEmpDetails().currentEmpDetailsElement().setPlatform(rs.getString(3));

wdContext.nodeEmpDetails().currentEmpDetailsElement().setPhNo(rs.getString(4));

wdContext.nodeEmpDetails().currentEmpDetailsElement().setCity(rs.getString(5));

}

its displaying only last row of the dbtable in table UIElement.

Thanks for your quick response,

Regards,

Shashikiran.B

Former Member
0 Kudos

you are setting all the values to the current context element.Instead of that you should be creating new element every time

while(rs.next()){

IEmployeeDetailsElement ele= wdContext.nodeEmpDetails().createEmployeeDetailsElement();

ele.setSNo(rs.getString(1));

ele..setName(rs.getString(2));

ele..setPlatform(rs.getString(3));

ele..setPhNo(rs.getString(4));

ele..setCity(rs.getString(5));

wdContext.nodeEmployeeDetails().addElement(ele);

}

Former Member
0 Kudos

hai shashi,

What sudhir has given is right.try to follow that.

Thanks n Regards

Sharanya.R

Former Member
0 Kudos

Hi Sudhir,

Thanks for your help i solved my problem. now i am able to get all records .

Thanks,

Shashikiran

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Iterate through the result set object

populate the context node

Ex:Replace the context nodeName with that of yours.


ResultSet resultSet = stmt.getResultSet();
	  //Iterate through the resultset
	  while(resultSet.next())
	  {
		  //Create element of the context node
		 IWDNodeElement nodeElement = wdContext.nodeOrders().createElement();
		 //assign value from the database to the context attribute
		 //Replace attributeName with your attribute name
		 //Replace value with resultSet.getShort("<ColumnName>")
		 nodeElement.setAttributeValue(attributeName, value);
		 //Add the element to your node
		 wdContext.nodeOrders().addElement(nodeElement);
	  }

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

you better post your code populating the webdynpro node.I guess you are not doing the

nodeXX.addElement(element);

inside the for loop

Regards,

Sudhir

Former Member
0 Kudos

Hi Ayyapparaj,

Thanks for your quick response.

I tried by replacing following code in your code snippet.

while(rs.next()) {

IWDNodeElement nodeElement = wdContext.nodeEmpDetails().createElement();

nodeElement.setAttributeValue(SNo, rs.getString(1));

wdContext.nodeEmpDetails().addElement(nodeElement);

}

but its showing error at SNo which is my Context attribute element.

Can you please help me how should i put my Context attribute in your code snippet.

And more over i have to display 5 columns so

should i create 5 elements by using above code.

Can you please Help me as soon as possible.

Thanks in advance

Regards,

Shashikiran.