Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners how to retreive data from database of a particular user after login

Have Programming Question? Ask it here!
 
 
 


monica patil
how to retreive data from database of a particular user after login
5 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners


hi I m developing a project on hospital management and I m not able to retrieve the user information..

now their is a login and registration page for newuser. after the user has filled the form he should go to the welcome page where he could see the information he has filled in the form and various other links..

now my question is how to retrieve this information of user after registration or after he has logged in...


Advertisement
View Answers

June 21, 2011 at 6:00 PM


1)login.jsp:

<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
 alert("Enter Username!");
  return false;
}
if(password==""){
 alert("Enter Password!");
  return false;
}
return true;
}
</script>
<form name="form" method="post" action="check.jsp" onsubmit="javascript:return validate();">
<table>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td></td><td><input type="submit" value="Login"></td></tr>
<tr><td></td><td><a href="register.jsp">Register Here</a></td></tr>
</table>
</form>
</html>

2)check.jsp:

<%@page import="java.sql.*"%>

<%
try{
String user=request.getParameter("user");
String pass=request.getParameter("pass");
 Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'");
           int count=0;
          while(rs.next())
          {
                              count++;
          }

                    if(count>0){
            out.println("welcome "+user);
            Statement s=con.createStatement();
           ResultSet rst=s.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'");
          while(rst.next()){
              System.out.println(rst.getString("firstname"));
            %>
            <h3>Your Account Information</h3>
            <table>
            <tr><td>FirstName:</td><td><input type="text" name="name" value="<%=rst.getString("firstname")%>"></td></tr>
            <tr><td>LastName:</td><td><input type="text" name="name" value="<%=rst.getString("lastname")%>"></td></tr>
            <tr><td>Address:</td><td><input type="text" name="name" value="<%=rst.getString("address")%>"></td></tr>
            <tr><td>Contact No:</td><td><input type="text" name="name" value="<%=rst.getString("contactNo")%>"></td></tr>
            <tr><td>Email:</td><td><input type="text" name="name" value="<%=rst.getString("email")%>"></td></tr>
           </table>
            <%
          }
          }
          else
          {
                       response.sendRedirect("login.jsp");
          }
}

catch(Exception e){
    System.out.println(e);
}
%>


June 21, 2011 at 6:01 PM


3)register.jsp:

<html>
<script>

function validate(){
     if(document.form.uname.value == ""){
        alert("Please enter user name." );
        document.form.uname.focus();
        return false;
    }
    if(document.form.fname.value == ""){
        alert("Please enter first name." );
        document.form.fname.focus();
        return false;
    }
     if(document.form.lname.value == ""){
        alert("Please enter last name." );
        document.form.lname.focus();
        return false;
    }

    if(document.form.address.value == ""){
        alert("Please enter address." );
        document.form.address.focus();
        return false;
    }
    if(document.form.contact.value == ""){
        alert("Please enter contact no." );
        document.form.contact.focus();
        return false;
    }


     if(document.form.city.value == ""){
        alert("Please enter city." );
        document.form.city.focus();
        return false;
    }


        return true;

   }  
</script>
<form name="form" method="post" onsubmit="return validate();" action="insertdata.jsp">
<table>

<tr><td>Enter First Name</td><td><input type="text" name="fname"></td></tr>
<tr><td>Enter Last Name</td><td><input type="text" name="lname"></td></tr>
<tr><td>Enter User Name</td><td><input type="text" name="uname"></td></tr>
<tr><td>Enter Password</td><td><input type="password" name="pass"></td></tr>

<tr><td>Enter Address</td><td><input type="text" name="address"></td></tr>
<tr><td>Enter Contact No</td><td><input type="text" name="contact"></td></tr>
<tr><td>Enter Email</td><td><input type="text" name="email"></td></tr>
<tr><td></td><td><input type="submit" value="Add" name="button"></td></tr>
</table>
</form>
</html>


June 21, 2011 at 6:01 PM


4)insertdata.jsp:

<%@page import="java.sql.*,java.util.*"%>
<table>
<%
String uname=request.getParameter("uname");
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String pass=request.getParameter("pass");
String address=request.getParameter("address");
int contact=Integer.parseInt(request.getParameter("contact"));
String email=request.getParameter("email");

        try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
        Statement st=con.createStatement();
        int i=st.executeUpdate("insert into login(username,password,firstname,lastname,address,contactNo,email) values('"+uname+"','"+pass+"','"+fname+"','"+lname+"','"+address+"',"+contact+",'"+email+"')");
        out.println("Data is successfully inserted into database.");
        ResultSet rs=st.executeQuery("Select * from login");
        if(rs.last()){
            %>
            <tr><td>User Name</td><td><input type="text" value="<%=rs.getString("username")%>"></td></tr>
            <tr><td>First Name</td><td><input type="text" value="<%=rs.getString("firstname")%>"></td></tr>
            <tr><td>Last Name</td><td><input type="text" value="<%=rs.getString("lastname")%>"></td></tr>
            <tr><td>Address</td><td><input type="text" value="<%=rs.getString("address")%>"></td></tr>
            <tr><td>Contact No</td><td><input type="text" value="<%=rs.getInt("contactNo")%>"></td></tr>
            <tr><td>Email</td><td><input type="text" value="<%=rs.getString("email")%>"></td></tr>
            <%
          }
                    con.close();

        }
        catch(Exception e){
        System.out.println(e);
        }
        %>
        </table>


March 21, 2012 at 6:16 PM


really helpful.........thanxxx....:)



February 23, 2014 at 6:43 PM


here after once insertion takes place no another insertion is going on tell me the reason please



Related Tutorials/Questions & Answers:
how to retreive data from database of a particular user after login
how to retreive data from database of a particular user after login  ......please help in display details of particular student after he login ...i want to display the details of only current user who logged
how to retreive data from database of a particular user after login
how to retreive data from database of a particular user after login  ... my question is how to retrieve this information of user after registration... the user information.. now their is a login and registration page for newuser
Advertisements
retreive integer data from database
retreive integer data from database  i made a table named result...=lalit&database=mydb"); String url="select marks from student where rollno... and two buttons "ok" and "cancel" i want to take input from textfield
How retreive data from database without using post method in jsp - JSP-Servlet
How retreive data from database without using post method in jsp  Tell me how?  Hi Friend, If you don't want to use post method then use... the selected value from the combo box and get textbox value from another page
how to retrive the particular data from database in php with mysql?
how to retrive the particular data from database in php with mysql?  ..._db("samp", $con); $Name=$_POST['unames']; $data=mysql_query("SELECT * FROM tbl_sample where Name='$Name'"); /*$info=mysql_fetch_array($data);*/ while
how to retreive data dynamically from mysql to drop down list
how to retreive data dynamically from mysql to drop down list   sir... fron end using jsp , after storing the data successfully .i want to retrieve the data of a particular column in a table into drop down list dynamically
JSP data after login where different users data are stored in database
and then after they can login. my question is how a user can see only his data after login... of that particular user will get retrieved from the database and displayed it on the welcome...JSP data after login where different users data are stored in database 
how to send sms from my website to mobile of particular user.
how to send sms from my website to mobile of particular user.  i had created a website and aim of pjt is whoever the client register for site..... so can u tell the process and how to implemnt this using java
Selecting particular data from multiple tables at database and perfoming calculations
Selecting particular data from multiple tables at database and perfoming calculations  Hi fnds, I want to maintain the financial database of 20... - month1,month2,....,upto month12.. each table contains the data like name,amount,paiddate
simple code to login user & authenticate it from database mysql
simple code to login user & authenticate it from database mysql  Sir, I am creating a login page which contain userid & password. Iwant to authenticate user from mysql database. please tell me the code for it. Thanks
how can i send a mail to a particular user from a many user dropdown list in jsp
how can i send a mail to a particular user from a many user dropdown list in jsp  how can i a sent a user question to a particular person from a drop down list in jsp
How to view database for user when they login in netbeans and mysql?
How to view database for user when they login in netbeans and mysql?  I create a web page where when user login they have to fill in a form, after... but it come out with all the other user information too. I'm using netbeans and mysql
how to write to java program to get the particular data from the website
how to write to java program to get the particular data from the website   i have to get the particular data by selecting the just numbers.. from the site .. how to get the ful details from the website by clicking the number
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file
how to retreive values from MS Access Database based on the values entered... Solution field from database and display in the textbox of the jsp.   1... * from item where itemid='"+id+"'"); while(rs.next()) { data = ":" + rs.getString
How to retrive a particular record from database in php with mysql?
How to retrive a particular record from database in php with mysql?  Am using phpMyAdmin Database.In mysql database having 10 records. The field... record based on username and password. I dont know how to retrive in php with mysql
How to Restore The Lossed data in MYSQL database after the System is formatted
How to Restore The Lossed data in MYSQL database after the System is formatted  How to Restore The Lossed data in MYSQL database after the System is formatted
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to create alert message after data submitted into database
how to create alert message after data submitted into database  I want to create alert message box after data stored into database and redirect to another page, how to do
how to retrieve data from database
how to retrieve data from database  unable to retrieve data from database using mySQL by using jsp sessions and beans for editing
How to retreive data by using combo box value - JSP-Servlet
How to retreive data by using combo box value  I am using a single jsp form.. i did not get from another form.. i do not use 2 jsp form.. all... there... /// Here stored Combobox values from database
User Registration Form Using JSP(JspBeans) after that how i can insert in database
User Registration Form Using JSP(JspBeans) after that how i can insert in database   User Registration Form Using JSP(JspBeans) after that how i can insert in database
How to prevent from navigating to a page after reaching Login page using back button?
How to prevent from navigating to a page after reaching Login page using back... there are buttons that opens pdf files in new window.The problem is when i goback to user login page using back button and agin click browser forward button,the 2nd page
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
How to retreive data by using combo box value - JSP-Servlet
How to retreive data by using combo box value  Hello friend , i am using only one form. U are using html form and jsp form. So get the values from html. So u r using if(request.getParameter("cid")!=null
login data
the data after login i want to show particular data for particular user means if i login i wanna see only myn data how shud i do thanxx in advance...login data   Hiiii Sir I am doing banking project on Asp.net i have
login data
the data after login i want to show particular data for particular user means if i login i wanna see only myn data how shud i do thanxx in advance...login data  Hiiii Sir I am doing banking project on Asp.net i have
how to use bean to retrieve data from database
how to use bean to retrieve data from database  how to use bean to retrieve data from database   poda sendru
How to use filter to redirect to login page after session timeout.
How to use filter to redirect to login page after session timeout.  ... session timeout . means if screen is inactive for a particular period of time then automatically it should redirect to login page from where user has
How to use filter to redirect to login page after session timeout.
How to use filter to redirect to login page after session timeout.  ... session timeout . means if screen is inactive for a particular period of time then automatically it should redirect to login page from where user has
How to insert image in sql database from user using servlet
How to insert image in sql database from user using servlet  pls tell me accept image from user and insert image in sql server 2005 database using servlet and jsp
How to insert and retreive an image in mysql database using spring mvc framework???
How to insert and retreive an image in mysql database using spring mvc framework???  I ve solved this problem based on the Product Search Application. Those who need this concept and code segment kindly copy it. Thanks and All
How to show data from database in textbox in jsp
How to show data from database in textbox in jsp   How to show data from database in textbox in jsp   Here is an example that retrieve the particular record from the database and display it in textbox using JSP. <
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  //Customer Name: <select name="name"> <% try{ Class.forName...="select * from staff"; ResultSet rs=st.executeQuery(sql); while(rs.next
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file...+",'"+email+"')"); out.println("Data is successfully inserted into database...(); in the below example. the error is "cannot convert from java.sql.Statement
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  Customer Name:<select name="name"> <% try{ Class.forName...=con.createStatement(); String sql="select * from staff"; ResultSet rs
How to use filter to redirect to login page after session timeout
How to use filter to redirect to login page after session timeout  ... timeout . means if screen is inactive for a particular period of time then automatically it should redirect to login page from where user has to login again
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  Can anybody tell me what is the problem in this code as i am not able to fetch the data from... tutorial go through the link JSP Get Data Into Dropdown list From Database   
How to prevent from navigating to ck buttonnext page when user reaches login page using back button
How to prevent from navigating to ck buttonnext page when user reaches login... goback to user login page using back button and agin click browser forward button... document opens..But i dont want it to happen.Instead,it should again ask for login
How to display data from database in a TableView
How to display data from database in a TableView  I need to populate a TableView (JavaFx) with database items. I designed the TableView in JavaFx... at this. The classes: This is the Class that creates the database data object: import
Login Form
; Login form in struts: Whenever you goes to access data from database, as a register user you are always asked for the login to accessing data. E-mail's login are very  good example
how to genrate login id and password after submitting the sign up form?
how to genrate login id and password after submitting the sign up form? ... i want 2 knw that after user submit all the details i that sign up form than how he will get their login id nd passwrd automatically
How to Display Username After Login in JSP
How to Display Username After Login in JSP In this section we will discuss how to display the Username and password after the successful login. In JSP... request.getParameter() method you can retrieve the username and password from the login
Retrieve data from database by using sql tag of JSTL SQL library
we will see how retrieve data from database using sql query given by user... Retrieve data from database by using sql tag of JSTL SQL library... to create data source for specified driver, user name and password of database
How to Display Next question from database after clicking Next Button using "Arraylist concept"
How to Display Next question from database after clicking Next Button using... with the Particular TopicId*/ int a=Integer.parseInt... with the particular TopicId Ends Here*/ int cardTopicid
How to Retrieve Data from the database and write into excel file using Java
How to Retrieve Data from the database and write into excel file using Java  Hi, I am trying to develop an small application where i trying to retrieve Data from the database and store the details in excel file. Please can
file share to particular user
a file to specific user , how to write code plzzz help. thank you in advance..._desc,up_date from files where user_id='"+i+"' "); while(rs.next()){String id...(); rs = st.executeQuery("select * from user_det"); int i=0; while(rs.next
how to display data into textboxes which is retrieved from the database
how to display data into textboxes which is retrieved from the database  I would like to know how to display data into textboxes which is retrieved from database in jsf. could you please provide a small example of how to do
 

 

 

DMCA.com