Posted by: nepali8 August 6, 2013
Java Servlet
Login in to Rate this Post:     0       ?        
 @ twitter

First off thanks for ur reply, Yes i am using my SQL server and i am just using simple JSP servlet. I have created all pojo class that requires, aslo have DAO layer and service layer as well. The screen shot  that i have shared with all after varified user is login into the account(home page).  My Questions:

how/what should i implement or put a method  in DAO layer so that it will connect to database and fetch data just for current user, when the respective user clicks on (profile information tab.). below is code snippet.  Thanks 


public static Connection getConnection(){
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/pageproject", "root", "root");
}catch(ClassNotFoundException e){
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
 
@Override
public boolean checkValidCustomer(String userName, String passWord) {
Connection conn=getConnection();
String query="Select * from admin Where username='" + userName + "' and userPassword='"+passWord+ "'";
Statement stmt;
ResultSet rs = null;
try {
stmt=conn.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true){
return true;
}
else{
System.out.println("Please enter valid UserName and Password");
}
 
} catch (SQLException e) {
e.printStackTrace();
}
try {
rs.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
 
/*@Override
public void getCustomerInfo() {
Connection conn = getConnection();
String query="select * from customerinfo where firstName='" + userName +"';";
Statement stmt;

}*/




public class Contact {
private String userName;
private String passWord;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}


}

package com.kumar.form;

public class CustomerProfile {
private String firsName;
private String lastName;
private String billAddress;
private String contactPh;
private String emailID;
public String getFirsName() {
return firsName;
}
public void setFirsName(String firsName) {
this.firsName = firsName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getBillAddress() {
return billAddress;
}
public void setBillAddress(String billAddress) {
this.billAddress = billAddress;
}
public String getContactPh() {
return contactPh;
}
public void setContactPh(String contactPh) {
this.contactPh = contactPh;
}
public String getEmailID() {
return emailID;
}
public void setEmailID(String emailID) {
this.emailID = emailID;
}

}

public class CustomerLogin extends HttpServlet{
/**
*/
private static final long serialVersionUID = 1L;

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String userName=req.getParameter("userName");
String passWord=req.getParameter("passWord");
ICustomerService logincheck=new CustomerService();
boolean result= logincheck.checkValidCustomer(userName, passWord);
if(result==true){
resp.sendRedirect("success.jsp");
req.getSession().setAttribute("userName", userName);
}else{
resp.sendRedirect("login.jsp");
}
}

}



@atrix

Thanks 

Read Full Discussion Thread for this article