• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need Help with Java

 
ahmed yousry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the attached picture the 2nd Coumn with name "Artikel Beschreibu" is Blob Column and It has Text value. I Need help with showing on table screen the text that the user Entered and not as in the picture "[B@413feec" Anyone can guide me How I can do that? Thanks
Binary.jpg
[Thumbnail for Binary.jpg]
Error.jpg
[Thumbnail for Error.jpg]
 
Paweł Baczyński
Bartender
Posts: 1877
35
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[B@413feec is something that toString() method of byte[] would return.
If you want to display it correctly convert it to String using one of String constructors.
And then display that String instead of byte[].

And please post text, not screenshots.
 
ahmed yousry
Greenhorn
Posts: 18
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Pawel,

Thanks for your help but can you explain more please? or maybe you have an example? I still fresh in Java. Thanks again
 
Paweł Baczyński
Bartender
Posts: 1877
35
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somewhere in your program you have a byte array whuch you are trying to display. This is not going to work nicely.
Look at the example:There is an array declared at line 3. When I try to display it at line 4 I got something that is not useful at all.
So a way to display it is to convert byte[] to String using a constructor of String class (line 5).
The String is correctly displayed at line 6.

My output:
[B@1540e19d
It works! :)
 
ahmed yousry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Pawel, Now I understood very well What do you mean but Do you have an example How to do it with value entered by jTextFiled?
 
Paweł Baczyński
Bartender
Posts: 1877
35
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what do you mean.
Find a place where you try to display your byte array and replace it with the String. Unless I see your code I can;t help you more.
What exactly do you have problem with?
What do you mean by how to do it with value entered by jTextFiled?
 
ahmed yousry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code I used to try with Blob Column :


What mistake I did?
 
Paweł Baczyński
Bartender
Posts: 1877
35
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you convert text from text area (which is String) into byte array and then back to String?
Are the values inserted correctly into db?
 
ahmed yousry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The problem is the 2nd Column with name "GLBA_BESCHR" has blob data type so any text entered at jTextArea1 it get saved as "B@41feec" I want to show on the table the text that entered at jTextArea1. For example if I entered at jTextArea1 "Hello Pawel" It will show on the table "Hello Pawel" not "B@41feec" . got my point?
 
Paul Clapham
Sheriff
Posts: 21559
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the data type of the column is Blob, and using the setString() method doesn't write the contents of your string into the Blob correctly, you could consider using one of the setBlob() methods in PreparedStatement.
 
ahmed yousry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Paul,

Thanks for the great help but I guess I have one step to understand. How I can convert the String entered Text on jTextArea to Blob? Thanks and have good weekend
 
Winston Gutkowski
Bartender
Pie
Posts: 10571
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahmed yousry wrote:Thanks for the great help but I guess I have one step to understand. How I can convert the String entered Text on jTextArea to Blob?

Easiest is probably with a SerialBlob, which has a constructor that works with byte[]s. Alternatively, as Paul said, things like PreparedStatement can also convert your data directly.

However, since this is text, I suspect that a Clob (java.sql.Clob) might be more applicable.

Winston

PS: Please DontWriteLongLines; it makes your thread very difficult to read. I broke up your one above, but please read the link. Thanks.
 
ahmed yousry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Winston,

Thanks a lot for the help but Can you give me an example? Thanks again
 
Campbell Ritchie
Sheriff
Posts: 51349
87
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this discussion would fit better in our databases forum: moving.

I presume you have seen the SerialBlob API documentation. I don't think it is specifically described in the Java Tutorials, but the “Large Objects” section might have something in. I found this StackOverflow thread which might help. It looks simple enough.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic