Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • 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
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

MySQL Blob is shown being read as [B@da99836  RSS feed

 
Ranch Hand
Posts: 130
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been using Java and Hibernate for DAO. I stored a long text in on of the field which is MySQL blob and inserted the record in DB using MYSQL Query Browser. When I run select query it showing the string ok.

But When I read it in Java application and trying to show on JSP its been shown as [B@da99836. or some similar value. I debugged the application if its JSP issue.. even in Java application also its been read as same junk value.

Can someone help me with this.. Thanks in Advance.
 
Saloon Keeper
Posts: 5406
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you trying to show it, both in the JSP and in your Java code? Post relevant code excerpts.

Something like "[B@da99836" typically happens when the toString method is invoked  (directly or indirectly) on an object which does not meaningfully override that method.
 
Sheriff
Posts: 21719
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default toString format (if it's not overridden) is <class name>@<hash code as HEX>, and that's exactly what you're seeing here. The class name in this case is [B. The [ indicates it's an array; the B indicates the element type is byte. So what you're getting is a byte[], and you need to do something with that.
 
Sheriff
Posts: 24374
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have an array of bytes. You can convert that in to a String like this:



This may work or it may not; the database designers may have had some nonstandard way of putting a string of characters into a Blob. Why isn't it a Clob if it contains text?
 
Bala Tilak
Ranch Hand
Posts: 130
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

byte[] bytes = /* something */;
String correspondingString = new String(bytes);




Got it now. So BLOB should be a byte[] in Java, not the String. So either I have to go for CLOB mapped to String in Java, or Go for BLOB and mapped it to byte[] in Java.

MySQL  -- Java

BLOB --> byte[]
CLOB --> String.


Thanks you all. I can't update the DB now , so I have changed the filed to byte[] in Java mapping file and then converting it to String using new String(byte[]) after reading from DB.


 
No, tomorrow we rule the world! With this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!