Java Servlet - Sajha Mobile
SAJHA MOBILE
Java Servlet
Posts 4 · Viewed 4094 · Go to Last Post
nepali8
· Snapshot 0
Like · Likedby · 0
 Namaste  all java Developer!

included screen shot.
 
How do i fetch data from database which is just belong to current user when clicking (personal information TAB) using servlet, 
I know i have to pass current's user id, name, or anything which is related to the current user so that it will fetech data from database dynamically. But just couldn't figured it out. 
 
Thanks  in advance 
twitter
· Snapshot 154
Like · Liked by · 0
 your Question is little inclmplete.... Which databse are you using? Are you using any kind of frameworks like Spring or Struts or any ORM? 

However in general you have the application structure like this: 
You should have a pojo with all necessary fields like id, name, address etc. , generate getters and setters.
Use dao layer with jdbc or hibernate  to connect to the database. 
with response.getParameter pass the value to the JSP. 
in JSP render the fields inside HTML.

This is the overview structure of the process. If you have any specific problem with any part of code send me message.
Last edited: 05-Aug-13 10:37 PM
Atrix112
· Snapshot 177
Like · Liked by · 0
nepali8,there are a bunch of ways of doing it.
If i were you, I would look at Spring JDBC template and get it done but that may be a bit too much.
Try simple JDBC connection ..follow this : http://www.tutorialspoint.com/jdbc/jdbc-db-connections.htm
Beauty of knowing this is, it will provide you the base for all persistance templates.
 
The tutorial is pretty clear you should be able to set it up as you seem to have good grip on UI.
 
Now you start coding bro, i ll vote for Elisha nani ..She seems to be a nice lady!
Last edited: 05-Aug-13 11:12 PM
nepali8
· Snapshot 280
Like · Liked by · 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 

Please log in to reply to this post

You can also log in using your Facebook
View in Desktop
What people are reading
You might like these other discussions...
· Posts 4 · Viewed 196
· Posts 10 · Viewed 787 · Likes 1
· Posts 9 · Viewed 1183
· Posts 1 · Viewed 78
· Posts 1 · Viewed 92
· Posts 1 · Viewed 84
· Posts 12 · Viewed 626
· Posts 25 · Viewed 4015 · Likes 2
· Posts 3 · Viewed 656
· Posts 3 · Viewed 594



Your Banner Here
Travel Partners
Travel House Nepal