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;
}
>
> 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.
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
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') )>
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;
}
>