It's not a secret anymore!*
The moose likes JDBC and the fly likes Null error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Null error" Watch "Null error" New topic
Author

Null error

michael hagberg
Greenhorn

Joined: Jan 18, 2001
Posts: 4
I get a null error every time I try to get a ResultSet back from my Bean. I guess it is because I set my ResultSet to null when I start, but I have to do that or else I get error messages. I get very frustrated over this and would really appreciate help!!
I include the code:
JSP-page:


<%=kategori%>
<%}%>
Bean:

ThanX in advance
[This message has been edited by michael hagberg (edited January 18, 2001).]
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
What statement is causing the error? Do you have null data in your database?
[This message has been edited by Joe Paolangeli (edited January 18, 2001).]
michael hagberg
Greenhorn

Joined: Jan 18, 2001
Posts: 4
Im not really sure. The thing is, I use almost exact the same code for updating a table in the db and it works fine. It doesnt return anything (void). But when I try to return a RecordSet (which is the case here) I get a nullpointerexception.
So Ive tried a lot of things in the bean, I even checked the returning ResultSet and it does have values, that is to say it is not null. But somewhere a Null is reported. Im working on it now and to be honest I dont really understand what generates it, I THINK it is something with the ResultSet but... I am not sure :-(
Michal Harezlak
Ranch Hand

Joined: Jul 06, 2000
Posts: 185
Michael,
I am not sure, but that might have something to do with closing connection before extracting data from the ResultSet.

michael hagberg
Greenhorn

Joined: Jan 18, 2001
Posts: 4
tried that too. Funny thing is, I have one method working, named doInsert. I have that one in the same bean, cant you have that? It is so confusing, cause if I rename the working method to doInsert2 it doesnt work - I get... Null error!
It seems to me that is the same problem, maybe its not the methods? maybe there is something in the architecture that Ive missed!?
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
Yes, the closing of the connection is probably causing the null error.
My suggestion would be to process the resultset in the bean. You should define get and set methods for each field that is needed in your jsp. In your JSP you would reference these fields either by JSP property tags or by JSP expressions.
Hope this helps,
Joe
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You can't close a connection while a ResultSet is open. Closing the connection will close the ResultSet and set it to null. Remember, the ResultSet is not the actual data from the database, it is the way to get the data. Imagine if you did "select * from a" where a was a table with 10,000,000 rows. Would you really expect the resultSet to contain 10,000,000 rows worth of data?


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
michael hagberg
Greenhorn

Joined: Jan 18, 2001
Posts: 4
Yes, that was it! I was so sure I had the results in the Rs. Many thanks!
 
jQuery in Action, 2nd edition
 
subject: Null error