aspose file tools*
The moose likes JDBC and the fly likes regarding Retrival of multiple values from db using result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "regarding Retrival of multiple values from db using result set" Watch "regarding Retrival of multiple values from db using result set" New topic
Author

regarding Retrival of multiple values from db using result set

dilip satyaraghava
Greenhorn

Joined: Nov 22, 2011
Posts: 8
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

Joined: Aug 22, 2010
Posts: 3438
    
  47

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regarding Retrival of multiple values from db using result set
 
Similar Threads
error on get from resultset
how to improve my program code ?
how to get values in an object?
How to bind data to a Spring form input tag
Writing data into *.txt file using java