0

This is my java method:

    public static boolean addEmployee(Employee employee) {
        String sql = "SELECT addemployee(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";

        try (Connection conn = connect();
             PreparedStatement ps = conn.prepareStatement(sql)) {
            ps.setString(1, employee.getFirstName());
            .
            .
            .
            ps.execute();
            return true;
        } catch (SQLException e) {
            showMessageDialog(null, e.getMessage());
            System.out.println(e.getMessage());
        }
        return false;
    }

This is my PostgreSQL function:

CREATE OR REPLACE FUNCTION addEmployee(. . .)
    RETURNS BOOLEAN AS
$$
DECLARE
    existsCheck BOOLEAN;
    iddd        INTEGER;
BEGIN
    SELECT EXISTS(SELECT ed.username
                  FROM employee_data ed
                  WHERE ed.username = usernameAdd)
    INTO existsCheck;
    IF (SELECT existsCheck = FALSE) THEN
       .
       .
       .
    ELSE
        RAISE EXCEPTION 'Nazwa użytkownika jest zajęta!';
    END IF;
    RETURN TRUE;
END ;
$$

When the exception is thrown, I get such a message dialog: [image]1

Error message is gotten when I try to register and the username I put already exists. So I get the alert "Username is taken by someone, try else" (1 line on the screenshot). And I want to print only these words, without this second line on the screenshot.

How can I get rid of this second line?

2
  • show the code that you are getting error message at Commented Jan 7, 2021 at 18:19
  • Error message is gotten when I try to register and the username I put already exists. So I get the alert "Username is taken by someone, try else" (1 line on the screenshot). And I want to print only these words, without this second line on the screenshot. Commented Jan 7, 2021 at 20:16

1 Answer 1

0

Use String.split() to split tne exception message and print what needed.

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.