aspose file tools
The moose likes JDBC and the fly likes How to read and write binary Bytes in MySQL ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "How to read and write binary Bytes in MySQL ?" Watch "How to read and write binary Bytes in MySQL ?" New topic
Author

How to read and write binary Bytes in MySQL ?

Jim Smithian
Greenhorn

Joined: Sep 21, 2004
Posts: 18
Hello,

I am working on a Java-MySQL project to compute the hash value of a document using Java MessageDigest. The output is 16 bytes of type Java 'byte'. I store the value in MySQL CHAR types(using Jdbc). When I read back the stored value from MySQL using resultSet.getBytes(); the read hash value is not the same as the stored value. Some characters are differenet. I think the problem must be from a mismatch between MySQL and Java data types or a character coding format.

Can any body please help me how to solve this problem. What data types I should use in MySQL and Java? what character coding should I use?

Thanks for your help.

Jim.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26168
    
  66

Jim,
MySql 4 and above have a "binary" type. It will store your bytes without conversion.
[ March 02, 2005: Message edited by: Jeanne Boyarsky ]

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to read and write binary Bytes in MySQL ?
 
Similar Threads
comparing digest always return false. why?
Reading float, short from InputStream
Reading file and putting in an array
Understanding Byte Data and Character Encoding
B&S: Beginner Questions