Writing once to DB
I have a method, which link a particular student (studentId) to a number of modules (moduleId) and then call a method, createRegistration, which run the sql insert method.
Once the user has clicked on the 'Register Module' button on the JSP form, the method is called.
I want to make sure that once the information has been written into the database, and the user click on the 'Register Module' button again, that the same information is not written in the database.
private void writeToDataBase()throws SQLException, ClassNotFoundException,
IOException, ServletException, FileNotFoundException
{
moduleVector = (Vector) session.getAttribute( "moduleVector" );
studentBean = (StudentBean) session.getAttribute( "studentBean" );
Iterator i = null;
i = moduleVector.iterator();
session.setAttribute( "register", new Boolean(false));
if ( ! ((Boolean) session.getAttribute( "register" ) ).booleanValue() ) {
while ( i.hasNext() ) {
moduleBean = (ModuleBean) i.next();
srsBean.createRegistration( studentBean.getStudentId(),
moduleBean.getModuleId() );
}
session.setAttribute( "register", new Boolean(true) );
}else{
errorBean.setErrorType( "You have already register for these modules."
+ " Click on back button." );
request.setAttribute("errorBean", errorBean);
display( "Error.jsp" );
}
removeSession( "register" );
}
At the moment, my logic is wrong. Every time the user click the Register Module button, it write it to DB. How do I make sure it is only written once?

