aspose file tools*
The moose likes Beginning Java and the fly likes Data get corrupted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Data get corrupted" Watch "Data get corrupted" New topic
Author

Data get corrupted

Francois Tardif
Greenhorn

Joined: Jul 12, 2000
Posts: 9
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

Joined: Jun 13, 2000
Posts: 3340
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?

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Francois Tardif
Greenhorn

Joined: Jul 12, 2000
Posts: 9
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

Joined: Jun 01, 2000
Posts: 146
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

Joined: Jul 12, 2000
Posts: 9
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

Joined: Jun 13, 2000
Posts: 3340
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

Joined: Jul 12, 2000
Posts: 9
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

Joined: Jul 12, 2000
Posts: 9
And the caracter inserted can be anything but usually non common character I mean not corresponding to the english alphabetics.
Jim Kelliher
Greenhorn

Joined: Aug 16, 2000
Posts: 1
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 ).
 
Don't get me started about those stupid light bulbs.
 
subject: Data get corrupted