• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return type question?

 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Friends,
If a method's type is void do we need to have retun at the end like update method as bellow?
public void update( Connection conn ) throws SQLException {
int nUserId;
int nStatusId;

nStatusId = StatusTable.lookupName( conn, status );
nUserId = UserTable.lookupUserInitials( conn, userInitials );

PreparedStatement stmt = conn.prepareStatement("update bug set ID=?,bdesc=?,fixedDate=?,userID=?,contact=? where bugNumber=?");
stmt.setInt(1,nStatusId);
stmt.setString(2,desc);
stmt.setDate(3,fixedDate);
stmt.setInt(4,nUserId);
stmt.setString(5,contact);
stmt.setInt(6,bugNumber);

stmt.executeUpdate();

stmt.close();

return;
}
 
Dave Harpster
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No you do not.
dave
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave,
Thanks for the answer and just one last question that why I put return and compiler didn't give me error and it works fine?
Thanks,
Elahe
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you are allowed to specify that you want the method to end now and return control to whomever had it before, but don't return some value.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Dirk got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic