Hey Friends,
Developing an Online Shopping System.
Firstly had posted a code regarding MD5 Encryption and it was solved very quickly.
Require the same help again.
While registering an image selected by the User should be inserted into the Database.
Posting a Code which follows the DAO Pattern but i don't know what to insert in the Method to allow it to insert the image into the database.
Thanking You all in advance
public void AddUser(String UserID , String FirstName , String MiddleName , String LastName , String Age , String MobileNumber , String Gender , String City , String EMail , String Username , String Password , String HashWord , String FileName)
throws ClassNotFoundException , SQLException , NoSuchAlgorithmException , FileNotFoundException
{
try
{
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(Password.getBytes());
BigInteger Hash = new BigInteger(1 , md5.digest());
HashWord = Hash.toString(16);
Statement myStatement = ConnectToDatabase();
String SQLQuery = "INSERT INTO Users(FirstName , MiddleName , LastName , Age , MobileNumber , Gender , City , EMail , Username , HashWord , User_Image) VALUES ('" + FirstName + "' , '" + MiddleName + "' , '" + LastName + "' , '" + Age +"' , '" + MobileNumber + "' , '" + Gender +"' , '" + City + "' , '" + EMail + "' , '" + Username + "' , '" + HashWord + "' , '" + FileName + "')";
myStatement.executeUpdate(SQLQuery);
}
catch (ClassNotFoundException CNFE)
{
System.out.println(CNFE);
throw CNFE;
}
catch (SQLException SQLE)
{
System.out.println(SQLE);
throw SQLE;
}
catch (NoSuchAlgorithmException NSAE)
{
System.out.println(NSAE);
throw NSAE;
}
}
Registration Servlet
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Users;
import DataAccessObject.DAO;
import DataAccessObject.DAO_Interface;
import com.oreilly.servlet.MultipartRequest;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.Enumeration;
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 SaguWesker
*/
public class Registration 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");
DAO_Interface Dao = DAO.getDAOInterface();
Dao.AddUser
(
request.getParameter(""),
request.getParameter("FirstName"),
request.getParameter("MiddleName"),
request.getParameter("LastName"),
request.getParameter("Age"),
request.getParameter("MobileNumber"),
request.getParameter("Gender"),
request.getParameter("City"),
request.getParameter("EMail"),
request.getParameter("Username"),
request.getParameter(""),
request.getParameter("HashWord"),
request.getParameter("FileName"));
HttpSession Session = request.getSession();
String FirstName = request.getParameter("FirstName");
Session.setAttribute("FirstName", FirstName);
RequestDispatcher view = request.getRequestDispatcher("registration_complete.jsp");
view.forward(request, response);
}
catch (ClassNotFoundException CNFE)
{
System.out.println(CNFE);
}
catch (SQLException SQLE)
{
System.out.println(SQLE);
}
catch (NoSuchAlgorithmException NSAE)
{
System.out.println(NSAE);
}
finally
{
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}