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.

[1278 byte] By [Sideina] at [2007-11-27 8:26:50]
# 1
It is efficient.Other than that that is the way you do it. You can generalize by using mapping collections if you want to entertain yourself and you have a lot of them.
jschella at 2007-7-12 20:16:23 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Thanks, It works fine but takes up almost 100 lines in my code. Unfortunately, I get to make 3 more of them for other tables.
Sideina at 2007-7-12 20:16:24 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...