wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes database doesn't fill List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "database doesn Watch "database doesn New topic

database doesn't fill List

natasa jones
Ranch Hand

Joined: Aug 20, 2006
Posts: 45
Hi all!
i am trying to fill a List with values from a table..but i am having a hard time to do so!the problem is that it doesnt store any values in List and it returns java.lang.NullPointerException.my code is the following:

private static final String SQL_Movie_Categories = "SELECT MOVIE_CATEGORY_ID, DESCRIPTION from movie_category";

public List getMovieCategories() throws ServiceException {
MovieCategory movieCategory;
List movieCategoryList = null;
PreparedStatement preparedStatement = null;
Connection connection = null;
ResultSet resultSet = null;
try {

connection = dataSource.getConnection();
preparedStatement = connection.prepareStatement(SQL_Movie_Categories);
resultSet = preparedStatement.executeQuery();
try {
while (resultSet.next()) {

movieCategory = new MovieCategory();
System.out.println("id=" + movieCategory.getId());
System.out.println("the item fetched is:" + movieCategory.getDescription());

} catch (java.lang.NullPointerException exc) {
System.out.println("null pointer exception");
return movieCategoryList;
} catch (SQLException ex) { // Close connection,resultSet,prepareStatements etc...
where MovieCategory is a BO i have made,which has movie_description and movie_id Strings and get and set methods.

can anyone help???it prints the data of the first database record but then..it doesnt store it and has a NullPointerException.
thanks in advance!
natasa jones
Ranch Hand

Joined: Aug 20, 2006
Posts: 45
Well i finally found it!
i should have declared my list List MovieCategoryList=new ArrayList(). ;)
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

Thanks for posting the solution so that others who see this thread in the future can benefit.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link: http://aspose.com/file-tools
subject: database doesn't fill List
It's not a secret anymore!