File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
Register / Login
JavaRanch » Java Forums » Java » JDBC
Reply 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
Bartender

Joined: Aug 22, 2010
Posts: 1219

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.
 
 
subject: regarding Retrival of multiple values from db using result set
 
Threads others viewed
error on get from resultset
Writing data into *.txt file using java
how to improve my program code ?
how to get values in an object?
How to bind data to a Spring form input tag
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture