Rasshu
Rasshu

Reputation: 1799

Changing SQLException message? Java

When trying to insert some duplicate data into a JTextField, that message appears:

Duplicate entry '1' for key 'PRIMARY'

How could I change it to something more intuitive like "Code already registered in the system"?

Upvotes: 0

Views: 870

Answers (2)

someone
someone

Reputation: 6572

Before insert, using a select statement check whether the record is already in the data base. If already exist provide your user notification else insert the data.

Upvotes: 1

hologram
hologram

Reputation: 519

You can try this:

if (the user inserts duplicate data into a JTextField) {
     throw new SQLException("Code already registered in the system.");
}

That will allow you to change the message. Hope that helps a bit!

Upvotes: 0

Related Questions