• 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

How to read and write binary Bytes in MySQL ?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author & internet detective
Posts: 39789
797
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim,
MySql 4 and above have a "binary" type. It will store your bytes without conversion.
[ March 02, 2005: Message edited by: Jeanne Boyarsky ]
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!