cancel
Showing results for 
Search instead for 
Did you mean: 

database access from WDJava

Former Member
0 Kudos

Hi experts!!

I am trying to implement a WD Java with two views.

The first ones passes the selection parameters for the select statement (to acces the database) in the second one that will show the result of the select statement in table format.

So far i've implemented the first part:

When the user presses the 'Submit' button of the first view the following code is triggered. My question is how can i pass the data to the second view's table??? And in which method of the view??

IWDNode node = wdContext.getChildNode("TEST",0);

ITESTElement test = wdContext.nodeTEST().currentTESTElement();

String name = (String) test.getAttributeValue("NAME");

String surname = (String) test.getAttributeValue("SURNAME");

InitialContext ctx;

try {

ctx = new InitialContext();

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

Connection con = ds.getConnection();

String SelectStmt = "select * from IR_TETS where "

+ "where NAME = '" + name + "'" ;

PreparedStatement stmt = con.prepareStatement(SelectStmt);

ResultSet resultSet = stmt.executeQuery();

Please help!!!

Thanx in advance!!!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ayyapparaj!

I changed :

1) my element in the database table and turned it to integer

2) i re-deployed my dictionnary project

3) my context element in the database is integer

and still i get this message:

The method setAttributeValue is not applicable for the arguments

(String, int)

Former Member
0 Kudos

Hi,

Give a try with the following code

element.setAttributeValue("Age", new Integer(resultSet.getInt("AGE")));

If this doesnt help can you post the stack trace.

Regards

Ayyapparaj

Answers (5)

Answers (5)

Former Member
0 Kudos

Ayyapparaj,

Once again thank you for your reply!!!!

Regards,

Iria

Former Member
0 Kudos

Can i ask one more thing???

What if i did not have only value to select from the table??

Something like..

Select * from <table> where name between <value1> and <value2> ..

How could we do that in java??

THANX IN ADVANCE!!

Former Member
0 Kudos

Hi,

Select * from <table> is not a good practice it impacts the performance.

You can do it even in java.

their wont be any change in the code but if you want all columns from the result set you need to write respective get and populate the contexts accordingly.

Regards

Ayyapparaj

Former Member
0 Kudos

Ayyapparaj,

it works fine!!!

I also tried this one:

element.setAttributeValue("AGE" , resultSet.getObject("AGE"));

and it works too!!!

I am posting it in case any one else needs it.

Thank you for all your help!!!

Best Regards,

Iria

Former Member
0 Kudos

Hi Ayyapparaj!!

Thank you for your reply!!

The code you sent works just fine, but the following line has a problem

element.setAttributeValue("Age", resultSet.getInt("AGE"));

I searched the setAttributeValue method but could not find why it does not work with integers.

I set the AGE to String and it works fine!!

THANX AGAIN!!!

Former Member
0 Kudos

Hi,

While creating the table what was the datatype of "AGE"?

If its string you have to use the string.

That could be one the issue related with the error in the following line

element.setAttributeValue("Age", resultSet.getInt("AGE"));

Pl have a check at the backend (database) datatype and make use of it.

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

Create a node which contains two attributes

Ex:

Details Cardianlity 0..n

Name String

Age integer

Following code will help you to populate the context created above using the data fetched from DB


InitialContext ctx;
	  try {
		  ctx = new InitialContext();
		  DataSource ds = (DataSource)ctx.lookup( "jdbc/SELECT_POOL");
		  Connection con = ds.getConnection();
		  String SelectStmt = "select NAME,AGE from IR_TETS where "
		  + "where NAME = '" + name + "'" ;
		  PreparedStatement stmt = con.prepareStatement(SelectStmt);
		  ResultSet resultSet = stmt.executeQuery();
		  
		  while (resultSet.next())
		  {
			  IWDNodeElement element = wdContext.nodeDetails().createElement();
			  element.setAttributeValue("Name", resultSet.getString("NAME"));
			  element.setAttributeValue("Age", resultSet.getInt("AGE"));
wdContext.nodeDetails().addElement(element)
		  }
		  
	  }catch (Exception e) {
		// TODO: handle exception
	}

Now bind this node to the table

If their exists records in db you will be able to see them

Regards

Ayyapparaj