Results 1 to 3 of 3

Thread: Personal info

  1. #1
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Question Personal info

    Hi all...

    I am making a GUI where I want to print out the personal info of a specific user who is logged in... I have the query set up and it retrieves the personal information but only the first row in the database. e.g I log on my 'admin' account it shows my info and if I log a friends account It give me my info aswell not the friends information

    Here's the query:
    public String info()
    {
    StringBuffer sb = new StringBuffer();
    try
    {
    Statement stmt = conn.createStatement();
    ResultSet b = stmt.executeQuery("SELECT Age, Gender, DateOfBirth, name, Surname FROM User");

    while (b.next())
    {
    String age = b.getString("Age");
    String gen = b.getString("Gender");
    String DOB = b.getString("DateOfBirth");
    String name = b.getString("name");
    String surname = b.getString("Surname");

    return "Personal Information: " + "\n" + "Name: " + name + "\n" + "Surname:" + surname + "\n" + "Age: " + age + "\n" + "Gender: " + gen + "\n" + "Date of Birth: " + DOB;
    }
    }
    catch (Exception e)
    {
    }
    return "not found";
    }
    -------------------------------------------------------------------------
    Here is the action It does when I try and call the information :

    if (event.getSource () == show)
    {
    WebConnection pc = new WebConnection ();
    nameA.setText (pc.info ());
    }

    Any help on how I can retrieve the data of the user thats logged in? Thanks:)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default

    Your query has no WHERE clause, so is returning everything from that table.
    Presumably you want to only retireve tha values where id/username/whatever matches that of the current user?

    Then, after getting all the users, you loop round the resultset, only to return at the end of the first loop...so of course it will return the first record it finds.

    On top of that, you don't close your Statement or your Resultset. This will result in cursor leaks on the db eventually causing an exception.

  3. #3
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default

    Thanks allot got to do it when I get to school program is on my school pc but I will get back when I get it working thanks :)

Similar Threads

  1. personal question for Eranga
    By fishtoprecords in forum Forum Lobby
    Replies: 23
    Last Post: 07-01-2008, 03:43 AM
  2. personal project
    By Prasun Banerjee in forum New To Java
    Replies: 3
    Last Post: 06-30-2008, 03:57 AM
  3. Personal Finance Manager R1.0.21
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-17-2007, 02:00 PM
  4. Personal Document Manager 0.6
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 08-11-2007, 10:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •