File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding Retrival of multiple values from db using result set

 
dilip satyaraghava
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while(rs.next())

{
funame[i]=rs.getString(1);
System.out.println(funame[i]);
fupwd[i]=rs.getString(2);
i++;
}

Doing this i am getting a NULL POINTER EXCEPTION.
How can i get rid of this problem??
 
Martin Vajsar
Sheriff
Pie
Posts: 3747
62
Chrome Netbeans IDE Oracle
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the exception actually occurs in the code snippet you've shown, then either i is null, rs is null, funame is null or fupwd is null.

Post full stack trace (obtained by catching the exception and invoking its printStackTrace method) and full source code of the class where the exception occurs, so that we can match line numbers from the stack trace with your code. We'll be able to provide better help then. Click TellTheDetails to see the why and how.

Foot note: there are few other possible improvements to your code:

1) Loading a list of users and their passwords from the database is probably a bad idea. User authorization should be done by other means, ie. selecting just the row from the database that matches given username and password; if a record is returned, the password matches, if no record comes back, the user or password is invalid. Moreover, passwords should be stored hashed in the database, but maybe you'Re already doing that.

2) Using lists instead of arrays is probably easier, less error prone and often more efficient.

3) Instead of two separate arrays, one array holding instances of class (say) User with attributes userName and password would probably be a better (and less error prone) design.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic