• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing database ResultSet to Disk file

 
Anant Desai
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program that reads records from a Database (Microsoft Access)
using an SQL query and writes records after performing some
calculations to a disk file(Windows 7) using the FileWriter class.
The problem: If any database field has spaces in it, it writes
"NULL" in the file instead of spaces. What am I doing wrong?
 
Tony Docherty
Bartender
Posts: 3054
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

This isn't the best forum for your post so I've moved this thread to the database forum.

Can you show the relevant code so we can see what you are actually doing.
When you say a database field has spaces in it do you mean when it only has spaces in it or does the problem also occur if there is text and spaces in a field?
 
Anant Desai
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a snippet of the code:



Here set is the ResultSet returned from the Select statement.
Field 1 is a Text field of length 18.
It may contain a string or it may be blank.
If TEXT1 field is blank, the program writes the word "NULL"
to the file.
 
Paul Clapham
Sheriff
Posts: 21583
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll find that if the database field is null (not all blanks) then what you write to the file will be the word "null" (not "NULL"). That's how Java treats string concatenation when it encounters a null (not empty) string, it's nothing to do with JDBC at all. Perhaps that's what you meant? Make sure you understand the difference between null values and empty values in the database.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic