0
    String val = searchText.getText();

    System.out.println(val);
    System.out.println(tmp);
    if (tmp == "properShippingName") {
        try {

            String sql = "SELECT SDS_NUMBER, PRODUCT_NAME, PROPER_SHIPPING_NAME FROM APP.MASTER WHERE PROPER_SHIPPING_NAME LIKE ?";
            pst = conn.prepareStatement(sql);

            pst.setString(1, val);
            rs = pst.executeQuery();
            // System.out.println("rs");

            jTable1.setModel(DbUtils.resultSetToTableModel(rs));

        } catch (Exception e) {
            e.printStackTrace(System.out);
            JOptionPane.showMessageDialog(null, e);
        }

My first question is I want to run the query using like %val%. I want the query to return anything close to what the user inputs into the "searchText" text field. I can not seem to figure out how to get it to recognize the variable and still execute the LIKE constraint.

Any help would be greatly appreciated!

I do have a second question on the same topic but slightly different problem so I will post another thread.

1 Answer 1

1

You have to include the percent in your setString method call.

pst.setString(1, "%" + val + "%");

Now the like - statement works with this wildcards.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.