This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Storing sql null values as Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Storing sql null values as "0" " Watch "Storing sql null values as "0" " New topic
Author

Storing sql null values as "0"

Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
I am having a problem with the result of a query. My query is resultin in 3 column . Then I add the row toa an arraylist. Sometimes my result will be null, the 3 colums will return nothing, because there is not information available. How can I store those values as '0s' in my arrayList.
Thank you in advance

This is my code.

Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
It is part of JSP!! Where was it moved?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60764
    
  65

This has nothing at all to do with JSP and is now in the JDBC forum. As you have replied, apparently you found it!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I don't see anything at all in the post which makes it a post about JSP. It's obviously a post about JDBC.

Anyway you seem to have misunderstood the ResultSet.wasNull() method. It returns true if the previous column you read (via getString() or getInt() or whatever method) contained null. The way you use it in that code, it will always return null because there was no previous column read.

Example of how to use it:


However if you had interpreted those columns as numbers -- which they clearly are numbers -- instead of converting them to String, then you wouldn't have this problem. The getInt() method always returns zero when the underlying data is null.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing sql null values as "0"
 
Similar Threads
PreparedStatement (displaying records)
Performence issue:Write query directly in session bean or call storted procedure
Using a Bean for Retrieving Results Sets - Best Approach
Problem while inserting data into MS SQL table
Returning a 0 value error