Query assembly efficiency
I was just curious if there is a more efficient way to assemble a query based off of user input. I have eight fields that are filled out by the user but not all of them have to be filled out. I currently am assembling the query by looking at each field and appending cases to the ends of two strings: tables and values. I also have to do checks to see if this is the first item in the query assembly so I know whether or not to put ", " in front of the value. in the end, my code looks like:
if (!fieldA.getText().equalsIgnoreCase("")){
if (comma){
tables +=", tableName";
values +=", " + fieldA.getText();
comma =true;
}else{
tables +="tableName";
values += fieldA.getText();
}
}
//assemble the rest of the query
It just seems like a long, hard way to assemble the query.

