Results 1 to 3 of 3
Thread: Personal info
- 11-03-2010, 03:12 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
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:)
- 11-03-2010, 05:04 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 11-03-2010, 05:16 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
personal question for Eranga
By fishtoprecords in forum Forum LobbyReplies: 23Last Post: 07-01-2008, 03:43 AM -
personal project
By Prasun Banerjee in forum New To JavaReplies: 3Last Post: 06-30-2008, 03:57 AM -
Personal Finance Manager R1.0.21
By JavaBean in forum Java SoftwareReplies: 0Last Post: 11-17-2007, 02:00 PM -
Personal Document Manager 0.6
By JavaBean in forum Java SoftwareReplies: 0Last Post: 08-11-2007, 10:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks