Hello Friends.
It has been a long time since i posted my codes in the DaniWeb Forum.
I have a problem which is really preventing me from moving ahead in the Project.
My project requires me to develop a small quiz application with a registration functionality.
The registration functionality requires the password to be stored as MD5.
All Help Shall Be Highly Appreciated.
Thanking all the Expert Programmers of DaniWeb in Advance.
The code for the registration is as follows:
Add User Method in the DAO File
public void AddUser(String UserID , String FirstName , String MiddleName , String LastName , String Age , String MobileNumber , String EMail , String Username , String Password , String Course , String Role)
throws ClassNotFoundException , SQLException
{
try
{
Statement SQLStatement = getDatabaseConnection();
String SQLQuery = "INSERT INTO User(FirstName , MiddleName , LastName , Age , MobileNumber , EMail , Username , Password , Course , Role) VALUES ('" + FirstName + "' , '" + MiddleName + "' , '" + LastName +"' , '" + Age + "' , '" + MobileNumber +"' , '" + EMail +"' , '" + Username +"' , '" + Password +"' , '" + Course +"' , '" + Role +"')";
SQLStatement.executeUpdate(SQLQuery);
DestroySQLConnection();
}
catch (ClassNotFoundException cnfe)
{
System.out.println(cnfe);
throw cnfe;
}
catch (SQLException SQLE)
{
System.out.println(SQLE);
throw SQLE;
}
}
Add User Servlet which calls the method
package Librarian;
import DataAccessObject.DAO;
import DataAccessObject.OshwalDAO;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
*
* @author Sagu Wesker
*/
public class PotentialUserInsert extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
RequestDispatcher rd = request.getRequestDispatcher("Relay");
OshwalDAO Dao = DAO.getDAOInterface();
Dao.AddUser(
request.getParameter(""),
request.getParameter("FirstName"),
request.getParameter("MiddleName"),
request.getParameter("LastName"),
request.getParameter("Age"),
request.getParameter("MobileNumber"),
request.getParameter("EMail"),
request.getParameter("Username"),
request.getParameter("Password"),
request.getParameter("Course"),
request.getParameter("Role"));
HttpSession session = request.getSession();
String FirstName = request.getParameter("FirstName");
session.setAttribute("FirstName", FirstName);
out.println("<html>");
out.println("<head>");
out.println("<link rel = 'stylesheet' href='SiteCSS/style.css' type='text/css' />");
out.println("<title>" + FirstName + " Is Now Part Of The System</title>");
out.println("</head>");
out.println("<h3 class='RelayProjectionStyle'>The Record For "+FirstName+" Has Been Inserted Into The Database</h3>");
out.println("<h3 class='RelayProjectionStyle'>Click <a href='AdminMenu.jsp'>Here<a> To Return To Admin Menu</h3>");
out.println("</html>");
}
catch (ClassNotFoundException cnfe)
{
System.out.println(cnfe);
}
catch (SQLException SQLE)
{
System.out.println(SQLE);
}
finally {
out.close();
}
}
}