Parsing Issue

Greetings I have this string that is generated dynamically:

Select top 10 destination, timeofexecution, accountID, lastfillquantity, client, ordernumber, symbol, buysell, orderMarking, lastfillprice, traderID from Trade with (NOLOCK) where ((traderID= '2five' and accountID=' 91890705') or (traderID='monty' and accountID='') or (traderID='' and accountID='10013274') ) and client in ('client1','client2','client3')

I want to get with of the accoutID='' and traderID='' parts. this is a multidimensional array of [5][2] of jcomboboxes... but here is the code of the parsing that is done. any help would be appreciated...I start at one in the array b/c the values at index 0 I do something else to it....

for (int i=1; i<boxes.length;i++){

if (boxes[i][0].isVisible()==true){

temp[i][0]=(String) boxes[i][0].getSelectedItem();

}

if (boxes[i][1].isVisible()==true){

temp[i][1]=(String) boxes[i][1].getSelectedItem();

}

}

for (int i=1; i><temp.length; i++){

if (temp[i][0]!=null){

it=it+"(traderID='"+temp[i][0].trim()+"' ";

}

if (temp[i][1]!=null){

it=it+" and accountID='"+temp[i][1].trim()+"') or ";

}

}

it=it.substring(0,it.length()-3)+")";

return it;

}

>

[2226 byte] By [h2opologirly69a] at [2007-11-27 9:00:06]
# 1

for (int i=1; i><temp.length; i++){

if (temp[0]!=null){

it=it+"(traderID='"+temp[0].trim()+"' ";

}

if (temp[1]!=null){

it=it+" and accountID='"+temp[1].trim()+"') ";

}

if(i!=temp.length-1){

it = it+"or";

}

}

return it;

And use StringBuffer or StringBuilder for constructing the query as Strings are immutable.>

vinayak_ra at 2007-7-12 21:28:23 > top of Java-index,Java Essentials,Java Programming...
# 2

> for (int i=1; i><temp.length; i++){

> if (temp[i][0]!=null){

> it=it+"(traderID='"+temp[i][0].trim()+"' ";

> }

> if (temp[i][1]!=null){

> it=it+" and accountID='"+temp[i][1].trim()+"')

> +"') ";

> }

> [b]if(i!=temp.length-1){

>it = it+"or";

> /b]

> }

> return it;

>

> And use StringBuffer or StringBuilder for

> constructing the query as Strings are immutable.

vinayak_ra at 2007-7-12 21:28:23 > top of Java-index,Java Essentials,Java Programming...
# 3
So I should use Stringbuilde or Stringbuffer to get rid of the extra accountid='' and the extra traderid='' from r (traderID='monty' and accountID='') or (traderID='' and accountID='10013274') )?
h2opologirly69a at 2007-7-12 21:28:23 > top of Java-index,Java Essentials,Java Programming...
# 4

now I think I see your problem. I believe the problem, other than this whole process smells of bad coding decisions (Not sure without seeing all the code and knowing the requirements, and no, I do not want you to post it :) ), is that the combo box indexes on your form are mixed up. What you think are related boxes, are not. Check the indexes of you combos, try filling is sequential numbers as the text, then loop thru them all and print out the values, I think you will find the problem.

~Tim

Message was edited by:

SomeoneElse

SomeoneElsea at 2007-7-12 21:28:23 > top of Java-index,Java Essentials,Java Programming...
# 5
will some comboboxes have an value in it the other is left blank...so therefor it still princte the and accountID='' even though there is nothing there b/c it is !=null i added an and !="" but that didnt work out well....
h2opologirly69a at 2007-7-12 21:28:23 > top of Java-index,Java Essentials,Java Programming...
# 6

Getting closer

for (int i=1; i<temp.length; i++){

if (temp[i][0]!=null){

if(temp[i][0]!=""){

it=it+"(traderID='"+temp[i][0].trim()+"' ";

}

}

if (temp[i][1]!=null){

if (temp[i][1]!=""){

it=it+" and accountID='"+temp[i][1].trim()+"') or ";

}

}

}

it=it.substring(0,it.length()-3)+")";

return it;

output is this: Select top 10 destination, timeofexecution, accountID, lastfillquantity, client from trader where ((traderID= '2five' and accountID=' 91890705') or and accountID='10013274') or (traderID='bjj-mu3' (traderID='monty' and accountID='08127') )>

h2opologirly69a at 2007-7-12 21:28:23 > top of Java-index,Java Essentials,Java Programming...
# 7

THANKS EVERYONE FOR YOUR HELP BUT I FIGURED IT OUT... its a hack but it works..

for (int i=1; i<temp.length; i++){

if ((temp[i][0]!=null)&&(temp[i][1]==null)){

it=it+"( traderID='"+temp[i][0].trim()+"') or ";

}

if ((temp[i][0]==null)&&(temp[i][1]!=null)){

it=it+" ( accountID='"+temp[i][1].trim()+"') or ";

}

if ((temp[i][0]!=null)&&(temp[i][1]!=null)){

it=it+"( traderID='"+temp[i][0].trim()+"' and accountID='"+temp[i][1].trim()+"') or ";

}

}

it=it.substring(0,it.length()-3)+")";

return it;

}

>

h2opologirly69a at 2007-7-12 21:28:23 > top of Java-index,Java Essentials,Java Programming...
# 8
Is it on purpose that your for loops start counting from 1 rather than 0?
OleVVa at 2007-7-12 21:28:23 > top of Java-index,Java Essentials,Java Programming...
# 9
PS I believe you still need to distribute some of the Duke stars you've set at stake in old threads, even back to http://forum.java.sun.com/thread.jspa?threadID=5181014&start=10&tstart=0 in beginning of this month.
OleVVa at 2007-7-12 21:28:23 > top of Java-index,Java Essentials,Java Programming...