Well you will have to submit data and let controler(servlet) compare it against DB, if Employee ID already exist you will have to go back and display error message. Otherwise you continue with data processing.
Other option is to have this ID's retrived from DB before any page displayed, something like empty index page with 1 sec redirection to servlet whitch retrive data from DB and save them in the session. After that provide user with form to fill and you can check for duplicats. But I will not advice to use second option
peter_budo
Code tags enforcer
15,432 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 901
Well, first of all, it would be much safer and reliabe to use a PreparedStatement rather than a Statement.
Second of all, a JSP is meant for viewing, changes/actions should happen in a Servlet, and scriptlets should not be used at all in JSP.
Also, if you must actually check before inserting, use a Select. But simpler (if the item you would need to check is the Primary Key) is to simply attempt to insert it and catch the SQLException. If a Primary Key constraint violation is returned, the record already existed.
And the only thing you can do from the server side, is to return an error page, or return to the form. You can't pop up an alert before the submit, unless you want to attempt to use AJAX, as those alert popups that you are probably thinking of, are JavaScript and the JavaScript running on the client would have no access to the database.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494