returning data outside scope..
Hi
I am trying to read some data from an sql table, but I can't get it to return the data stored in my 'usr' ... The problem is obvious since usr is limited to the scope above the return but how can I structure the below code to circumvent the problem?
Code:
public static User getUserbyUid(int id)
{
try
{
Connection con = getConnection();
Statement s = con.createStatement();
ResultSet RS = s.executeQuery("SELECT * FROM users");
RS.next();
int ID = RS.getInt("id");
String userName = RS.getString("username");
String Psw = RS.getString("psw");
int startDate = RS.getInt("startdate");
User usr = new User(ID, userName, Psw, startDate);
}
catch (SQLException sqlgetUserbyUid)
{
System.out.print(sqlgetUserbyUid);
}
return usr;
}