• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data get corrupted

 
Francois Tardif
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a file to put data on a database.
In the file each column corresponding to my db is separated by ";".
I'm using this to read line by line :
LineNumberReader lnr = new LineNumberReader(new FileReader(file))
I put the variable in a string tokenizer. By the way the my column are varchar, int, int.
I don't have any problem with the int.
But with the string sometimes I a character is added in the db but when I looked this token the character added is not present.
Anybody had this problem?
I also try different manner to read the file but I always have this problem.
Can someone help me?
Thanks
Frank
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Francois Tardif:
Hi,
I have a file to put data on a database.
In the file each column corresponding to my db is separated by ";".
I'm using this to read line by line :
LineNumberReader lnr = new LineNumberReader(new FileReader(file))
I put the variable in a string tokenizer. By the way the my column are varchar, int, int.
I don't have any problem with the int.
But with the string sometimes I a character is added in the db but when I looked this token the character added is not present.
Anybody had this problem?
I also try different manner to read the file but I always have this problem.
Can someone help me?
Thanks
Frank

I hope I'm reading this right. Your file contains the information extracted from the database? If it is, then this is a seperate entity from the database and needs to be refreshed each time the database changes. Can I ask why aren't you connecting to the database directly using jdbc?
 
Francois Tardif
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I was not clear on this explanation.
I have data on a disk that I want to put in the db.
When I read the data on the disk they are correct. But after I put them in the db a character has been add on some row in the column String.
 
Milind Kulkarni
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I used readLine() of BufferedReader object to read the ASCII data for my application and I did not face any problems.
Regards,
Milind
 
Francois Tardif
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used this method too and I have the same problem.
The only thing I didn't try is the class FileInputStream to read the bytes.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Francois Tardif:
I think I was not clear on this explanation.
I have data on a disk that I want to put in the db.
When I read the data on the disk they are correct. But after I put them in the db a character has been add on some row in the column String.

How is the data loaded from the file to the database? SQL Loader or by your java program? What is the character inserted and where?
 
Francois Tardif
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To load the data I have a loop which one read each line until eof and put it in a string.
Each line data appears like this :
name;1;3
I'm using a string tokenizer to put this string in 3 variables. For example: szName, szIdColor, szIdType.
To put the data in the db I'm doing this :
Connection con...
....
while(szFileLine != null){
szInsertStatement = "INSERT INTO table1(NAME, IDCOLOR, IDTYPE)VALUES (?,?,?)";
PreparedStatement pstmt = con.prepareStatement(szInsertStatement);
pstmt.setString(1, szName);
pstmt.setInt(2, Integer.parseInt(szIdColor));
pstmt.setInt(3, Integer.parseInt(szIdtype));
pstmt.executeUpdate();
con.commit();
pstmt.close();
}//end while
during the filling I print on the console the value of szName, and there are fine. But when I look inside the db sometimes there is a character that has been added.
 
Francois Tardif
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the caracter inserted can be anything but usually non common character I mean not corresponding to the english alphabetics.
 
Jim Kelliher
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could be seeing things such as tab characters that were in your original file, and just became visible when you moved them to your db...if you read the file n bytes at a time into a byte array ( of comparable size ), you can scan the byte array for such characters and then remove replace them if you want ( or replace them with space(s) or whatever ).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic