/* RegistrationDAO*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.tcs.ignite.connectionname.DAO;
import com.tcs.ignite.connectionname.bean.Register;
import com.tcs.ignite.connectionname.util.Eyeconnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class RegisterDAO {
private Connection connection;
private connectionnamecon;
public RegisterDAO() {
con = new connectionname();
}
public boolean insertRecords(Register rg) throws Exception {
connection = con.openConnection();
String select="select * from register";
PreparedStatement ps=connection.prepareStatement(select);
ResultSet rs=ps.executeQuery();
while(rs.next())
{
String email=rs.getString("user_email");
if(rg.getUser_email().equals(email))
{
return false;
}
}
ps.close();
String query = "insert into register(user_Fname,user_Lname,password,confirm_pass,contact_no,user_email,user_address,user_pincode) VALUES (?,?,?,?,?,?,?,?)";
ps = connection.prepareStatement(query);
ps.setString(1, rg.getUser_Fname());
ps.setString(2, rg.getUser_Lname());
ps.setString(3, rg.getPassword());
ps.setString(4, rg.getConfirm_pass());
ps.setString(5, rg.getContact_no());
ps.setString(6, rg.getUser_email());
ps.setString(7, rg.getUser_address());
ps.setString(8,rg.getUser_pincode());
int rowcount = ps.executeUpdate();
con.closeConnection();
if (rowcount == 0) {
return false;
} else {
return true;
}
}
}
/*
RegistrationManager*/
*/
package com.tcs.ignite.connectionname.Manager;
import com.tcs.ignite.connectionname.DAO.RegisterDAO;
import com.tcs.ignite.connectionname.bean.Register;
public class RegisterManager {
public boolean insertManager(Register rg) throws Exception {
RegisterDAO regdao = new RegisterDAO();
boolean result = regdao.insertRecords(rg);
if(result==true)
{
return true;
}
else
{
return false;
}
}
}
/*RegistrationServlet*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
Register reg=new Register();
reg.setUser_Fname(request.getParameter("firstname"));
reg.setUser_Lname(request.getParameter("lastname"));
reg.setPassword(request.getParameter("password"));
reg.setConfirm_pass(request.getParameter("confirm_password"));
reg.setContact_no(request.getParameter("mobile"));
reg.setUser_email(request.getParameter("email"));
reg.setUser_address(request.getParameter("address"));
reg.setUser_pincode(request.getParameter("pincode"));
RegisterManager regManager=new RegisterManager();
if(regManager.insertManager(reg)){
// RequestDispatcher requestDispatcher= request.getRequestDispatcher("TCSBLUE.jsp");
// requestDispatcher.forward(request, response);
HttpSession session = request.getSession(true);
session.setAttribute("loginid", reg.getUser_email());
//out.print(session.getAttribute("loginid"));
out.write("Successfully Registered...");
}
else
{
// RequestDispatcher requestDispatcher= request.getRequestDispatcher("Error.jsp");
// requestDispatcher.forward(request, response);
out.write("Something is going wrong....");
}
}
catch(Exception ex)
{
Logger.getLogger(Connection.class.getName()).log(Level.SEVERE, null, ex);
}
finally {
out.close();
}
}