cancel
Showing results for 
Search instead for 
Did you mean: 

Display ResultSet in several columns

Former Member
0 Kudos

Hi all,

With this code:

try{
			InitialContext ctx = new InitialContext();
			DataSource ds = (DataSource)ctx.lookup("jdbc/MyAlias");
			Connection con = ds.getConnection();
			Statement sm = con.createStatement();
			ResultSet rs = sm.executeQuery("SELECT * FROM TABLE");
			while(rs.next())
			{
				IPrivateFlightInfoComponentView.IFlightContentElement element = wdContext.nodeFlightContent().createFlightContentElement();
				String result = rs.getString("COL1");
				element.setFlightValues(result);
				wdContext.nodeFlightContent().addElement(element);
				wdContext.nodeFlightContent().moveNext();
			}
			wdContext.nodeFlightContent().moveFirst();
	}
	catch(Exception e){
		wdComponentAPI.getMessageManager().raiseException(e.getMessage(),false);
	}

This code works, thanks to contribution from the forum.

My problem is; I want to return another column from DB and write it to a new column in IUTable.

String result = rs.getString("COL1")+rs.getString("COL2");

Will not work, logically because it will write to same column in the UITable.

In "Layout" I got a Table with one Column.

Is there a way I can solve this?

Regards,

Simon

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

Hello Simon,

1) Create another attribute in FlightContent node (Column2)

2) Add in your code


String result2 = rs.getString("COL2");
element.setCoulmn2(result2);

3) Add coulmn to table. Add cell editor and map value Coulmn2 to it,

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Hi Maksim Rashchynski,

I did those things and it worked if you add

2b) create new element in code (else expection)

But now as I described in former post every other field in column turns blank..

Guessing it has something with cardinality, singleton and selection in Context..?

Regards,

Simon

former_member182372
Active Contributor
0 Kudos

Hello Simon,

Are you initializing your attributes vith values from Result set as suggested?


...
String result2 = rs.getString("COL2");
element.setCoulmn2(result2);
...

Check table columns binding with new attributes.

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Hi Maksim Rashchynski,

Thanks for helping.

If I try to use the same element I get this error:

[code]

com.sap.tc.webdynpro.progmodel.controller.MessageManager$AbortMessageManagerException: Node(FlightInfoComponentView.FlightContent): cannot bind or add element, because it is already bound to a node

[/code]

So i have to create new element.

Hi Nagarajan,

Yeah that's what I have managed.

Now I get every other field blank.

C1 C2

a -

- b

c -

- d

.

.

.

Regards,

Simon

Former Member
0 Kudos

Hi simon,

where u r getting ur second column.u have given col 2 but u haven't got it inside the while loop.Plz do forward ur code so that we can find the bug in it.

Also make sure to give True for raiseException.Then only it will throw u the correct exception.

Hope this helps u,

Regards,

Nagarajan.

former_member182372
Active Contributor
0 Kudos

In case if you are using one recordset:

try{
			InitialContext ctx = new InitialContext();
			DataSource ds = (DataSource)ctx.lookup("jdbc/MyAlias");
			Connection con = ds.getConnection();
			Statement sm = con.createStatement();
			ResultSet rs = sm.executeQuery("SELECT * FROM TABLE");
			while(rs.next())
			{
				IPrivateFlightInfoComponentView.IFlightContentElement element = wdContext.nodeFlightContent().createFlightContentElement();
				String result1 = rs.getString("COL1");
				element.setFlightValues(result1);
				String result2 = rs.getString("COL2");
				element.setColumn2(result2);				wdContext.nodeFlightContent().addElement(element);
				wdContext.nodeFlightContent().moveNext();
			}
			wdContext.nodeFlightContent().moveFirst();
	}
	catch(Exception e){
		wdComponentAPI.getMessageManager().raiseException(e.getMessage(),false);
	}

I suggest you to rebuild your SQL queries to avoid 2 recordsets.

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Hi Nagarajan,

The code:


try{
			InitialContext ctx = new InitialContext();
			DataSource ds = (DataSource)ctx.lookup("jdbc/MyAlias");
			Connection con = ds.getConnection();
			Statement sm = con.createStatement();
			ResultSet rs = sm.executeQuery("SELECT * FROM TABLE");
			while(rs.next())
			{
				IPrivateFlightInfoComponentView.IFlightContentElement element = wdContext.nodeFlightContent().createFlightContentElement();
				String result = rs.getString("COL1");
				element.setFlightValues(result);
				wdContext.nodeFlightContent().addElement(element);
				IPrivateFlightInfoComponentView.IFlightContentElement ele2 = wdContext.nodeFlightContent().createFlightContentElement();
				String result2 = rs.getString("COL2");
				ele2.setFrom(result2);
				wdContext.nodeFlightContent().addElement(ele2);
				wdContext.nodeFlightContent().moveNext();
			}
			wdContext.nodeFlightContent().moveFirst();
	}
	catch(Exception e){
		wdComponentAPI.getMessageManager().raiseException(e.getMessage(),true);
	}

(changed to True in RaiseException)

I had to make new element aswell, else error.

Hi Maksim Rashchynski,

It has to be possible to display all columns in table in to a UITable, without rewriting query? Or am I wrong?

Regards,

Simon

PS: thanks for all your help.

Former Member
0 Kudos

Hi simon,

It is not neccessary to add element twice .try this code,it should work.

try{

InitialContext ctx = new InitialContext();

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

Connection con = ds.getConnection();

Statement sm = con.createStatement();

ResultSet rs = sm.executeQuery("SELECT * FROM TABLE");

while(rs.next())

{

IPrivateFlightInfoComponentView.IFlightContentElement element = wdContext.nodeFlightContent().createFlightContentElement();

String result = rs.getString("COL1");

element.setFlightValues(result);

String result2 = rs.getString("COL2");

element.setFrom(result2);

wdContext.nodeFlightContent().addElement(element);

wdContext.nodeFlightContent().moveNext();

}

wdContext.nodeFlightContent().moveFirst();

}

catch(Exception e){

wdComponentAPI.getMessageManager().raiseException(e.getMessage(),true);

}

hope this helps u,

Regards,

Nagarajan.

Former Member
0 Kudos

Hi Nagarajan,

Again you solved my problem! My error was adding the wdContext.nodeFlightContent().addElement(element); twice.

Thanks again!

Regards,

Simon

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

I managed to get the result now, just added columns to UITable and made new Value Attribute to it.

now they seem to come with an empty space every other field in columns, will do some serching on forum.

Regards,

Simon

Former Member
0 Kudos

Hi simon,

If i m correct u want to have values stored in the table from different resulsets right?

In that case u have to define a result set first add that values inside the table.Then define ur next resultset add that value then it would work.

Hope this helps u,

Regards,

Nagarajan.