[Show all top banners]

nepali8
Replies to this thread:

More by nepali8
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Java Servlet
[VIEWED 4814 TIMES]
SAVE! for ease of future access.
Posted on 08-05-13 2:36 PM     Reply [Subscribe]
Login in to Rate this Post:     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 

 
Posted on 08-05-13 10:29 PM     [Snapshot: 154]     Reply [Subscribe]
Login in to Rate this Post:     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

 
Posted on 08-05-13 11:01 PM     [Snapshot: 177]     Reply [Subscribe]
Login in to Rate this Post:     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

 
Posted on 08-06-13 2:06 PM     [Snapshot: 280]     Reply [Subscribe]
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;
}



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;
}

}
/**
*/
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 be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 30 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
I hope all the fake Nepali refugee get deported
ढ्याउ गर्दा दसैँको खसी गनाउच
To Sajha admin
Travel Document for TPS (approved)
All the Qatar ailines from Nepal canceled to USA
MAGA मार्का कुरा पढेर दिमाग नखपाउनुस !
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters