[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 3879 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 200 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration
What are your first memories of when Nepal Television Began?
निगुरो थाहा छ ??
ChatSansar.com Naya Nepal Chat
Basnet or Basnyat ??
Sajha has turned into MAGATs nest
NRN card pros and cons?
Do nepalese really need TPS?
कता जादै छ नेपाली समाज ??
susta manasthiti lai ke bhanchan english ma?
Nas and The Bokas: Coming to a Night Club near you
Will MAGA really start shooting people?
Democrats are so sure Trump will win
मन भित्र को पत्रै पत्र!
Top 10 Anti-vaxxers Who Got Owned by COVID
I regret not marrying a girl at least for green card. do you think TPS will remain for a long time?
TPS Work Permit/How long your took?
काेराेना सङ्क्रमणबाट बच्न Immunity बढाउन के के खाने ?How to increase immunity against COVID - 19?
Breathe in. Breathe out.
3 most corrupt politicians in the world
Nas and The Bokas: Coming to a Night Club near you
Mr. Dipak Gyawali-ji Talk is Cheap. US sends $ 200 million to Nepal every year.
Harvard Nepali Students Association Blame Israel for hamas terrorist attacks
TPS Update : Jajarkot earthquake
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