I have the following code for requesting 4 parameter, and then creating a query from them.
String reason = request.getParameter("REASON");
String task = request.getParameter("TASK");
String result = request.getParameter("RESULT");
String resultCause = request.getParameter("RESULT_CAUSE");
public boolean isRowInTable(String reason, String task, String result, String resultCause)
throws BusinessException {
PreparedStatement prepStmt = null;
ResultSet rs = null;
StringBuffer queryB = new StringBuffer("");
Boolean rowExists = null;
queryB.append("select ")
.append("* ").append("from ")
.append("TABLE_NAME ").append("where ")
.append("REASON = '").append(reason)
.append("' AND TASK = '").append(task)
.append("' AND RESULT = '").append(result);
if (!(resultCause == "")) {
queryB.append("' AND RESULT_CAUSE = '").append(resultCause);
}
queryB.append("'");
.
.
.
}
When creating a query, the resultCause parameter on the page can be empty, so after googleing for the empty request, I've found, that the value will be an empty String in this case: "". So when checking, if the row exists in the database, I try to transform the query accordingly, and only append the where caluse, if it's not empty. But it seems like I'm doing something wrong here. Am I checking the resultCause in a correct way?