I need to mantain a legacy application that fires a SQL query to search for items stored in different locations (i.e. station, slot and subslot). The current query appends the “AND (…)” section to the main query so it dynamically builds a more restrictive search criteria.
When the first if returns true (meaning the user typed something a the desktop application’s field and pressed Enter), I need to check if the data of jTextFieldPCA falls on any of the inner conditions. The value of the data is, typically, one single digit number, but it could be a letter as well.
The RegExes I’m attempting are these, but I’m missing something. How can I make sure a value of 6 to fall on the first inner condition, a value of 6.6 to fall on the second inner condition and a value of 6.6.6 to be captured by the third inner condition?
if (jTextFieldPCA.getText().compareTo("") != 0) {
if (jTextFieldPCA.getText().matches("[A-Za-z0-9]") ) {
strBuilder.append(" AND CAST(complist.Station AS VARCHAR) LIKE ");
}
if (jTextFieldPCA.getText().matches("[A-Za-z0-9]" + "." + "[A-Za-z0-9]") ) {
strBuilder.append(" AND CAST(complist.Station AS VARCHAR) + '.' + CAST(complist.Slot AS VARCHAR) LIKE ");
}
if (jTextFieldPCA.getText().matches("[A-Za-z0-9]" + "." + "[A-Za-z0-9]" + "." + "[A-Za-z0-9]") ) {
strBuilder.append(" AND CAST(complist.Station AS VARCHAR) + '.' + CAST(complist.Slot AS VARCHAR) + '.' + CAST(complist.SubSlot AS VARCHAR) LIKE ");
}
(...)
Thanks in advance,
gtludwig
Add a backslash just before the dot character