• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Storing sql null values as "0"

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is part of JSP!! Where was it moved?
 
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing at all to do with JSP and is now in the JDBC forum. As you have replied, apparently you found it!

 
Marshal
Posts: 25805
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic