• 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
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Can't understand Clob Error Exception

 
Ranch Hand
Posts: 99
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, forumists!

I am having a huge problem with a project of mine. I really need help fast since I have a deadline in a few days. The program is not that large at the moment but will be bigger in time. The problem is that I am trying to update a Clob object that store a large amount of text.The project I am working on is a job seeking-application where the user can store his or hers cv and make long notes from interviews.

The class that handles the update functionality in the program looks like the following:



Everything seem to work just fine but then I get big problems with the following method in the CompanyManager class



It throws the following error exception that I can't seem to understand or figure out what it means:



I hope this post is accurate to the standards of the ranch.  I am not that good at english so I can't describe a larger picture of the problem than what I've posted here. And I am sorry if the code I posted is too long.

Best regards,
Robert!


 
Master Rancher
Posts: 4371
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the full stack trace that comes with the exception?
 
Robert Ingmarsson
Ranch Hand
Posts: 99
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, Mr. Tolls!

Thank you so much for your reply! Here are the stacktrace that follows the exception:



/Robert!
 
Dave Tolls
Master Rancher
Posts: 4371
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah.
Right.
You are retrieving a Clob from the database in your getClob method, which has had free called against it (well, the ResultSet, but same effect).
That essentially closes the stream that the clob uses.

Why are you trying to create a Clob by editing an existing Clob?
If you just need to change the text then use the version of setClob that has a Reader parameter.
 
Robert Ingmarsson
Ranch Hand
Posts: 99
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, Mr. Tolls!

Thank you so much for your reply. It's very hard to describe the problem nearer than what I already have done. And then there is my english grammar. Put it basically, in my application I have a JTextArea object called "jTaResponse", this Is where the response from the company the user has contacted will be written into. In my application I have a JTable that the user navigates through that stores information such as company name, email address and phone number. Below the JTable there is a JTabbedPane that contains fields of form objects of different types. I wan't to use a clob to store the text that is written into my JTextArea object and then update that text in the update mode of the program. How can I accomplish this according to coding standards? I set the text of the clob object like the code below explains



And then in my update class I want to retrieve the clob object from a ResultSet in order to store the updated response-text the user has written into the JTextArea object. I can only think of one way to do this and that is what I have posted here



In your reply you mentioned a Reader object? Could you show me how a procedure like this is done in the real world? I would be so incredibly greatful since I am coding after a time limit meaning I have not that much time over for trial and testing. Hope I have been clear enough, pardon for leaving out more details of the project.

Very kind regards,
Robert!


 
Dave Tolls
Master Rancher
Posts: 4371
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have new text that you want to replace the existing Clob text.

So you need to use the setClob that uses a Reader.  Since your source data is a String, a StringReader would be the thing to use.



Do not get the original Clob just to change the data in it.
That's a complete waste of time, and the reason you are getting the exception.
 
Robert Ingmarsson
Ranch Hand
Posts: 99
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, Mr. Tolls!

I don't understand how you can update a clob object's text with a StringReader. Please forgive me if there is something I am missing. I wan't to write large text to an existing clob object. How can I accomplish that if I register a StringReader to a Clob that is set via a PreparedStatement? Can you show me a clearer example of how it should be done. Right now i am looking in to if there is a way to attach a Writer to a clob object and via that Writer update the clob with current text.

Best regards, Robert!
 
Sheriff
Posts: 24754
59
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Robert Ingmarsson wrote:How can I accomplish that if I register a StringReader to a Clob that is set via a PreparedStatement?



It's not you that accomplishes it, it's the JDBC driver. The process is, you use a Clob and attach a StringReader to it. Then when the JDBC driver executes the update, it handles the Clob by reading the data from the StringReader and updating the database with that data.
 
Robert Ingmarsson
Ranch Hand
Posts: 99
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, Mr. Clapham!

Thank you very much for your reply. I have now used a StringReader in the setClob method of my PreparedStatement in my update class and it seems to be working now, update-wise that is.  

Now I am wondering how I can get the text from the clob object that has a StringReader attached to it. Should I retrieve the StringReader and it's content from the PreparedStatement object or via a ResultSet using a sql query? This is way over my level of knowledge. Sorry for that.

Best regards,
Robert!

 
Robert Ingmarsson
Ranch Hand
Posts: 99
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, world!

I don't know, but could anyone tell me if I am on the right track in this clob updating problem of mine? First in my PreparedStaement method I have used a StringReader in the statement's setClob method in my update class. And in my so called CompanyVisitor class that handles the updating of my form objects. In this class I have a call to a function that extracts data from a clob fetched via a ResultSet like
below



I will appreciate any point of views from anyone that reads this post and can tell if I am close to a real world solution or not?

Very best regards,
Robert!
 
Paul Clapham
Sheriff
Posts: 24754
59
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Robert Ingmarsson wrote:Now I am wondering how I can get the text from the clob object that has a StringReader attached to it.



I don't know why you would want to do that. The StringReader was already wrapping a String -- so just use that String.
 
Paul Clapham
Sheriff
Posts: 24754
59
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Robert Ingmarsson wrote:I will appreciate any point of views from anyone that reads this post and can tell if I am close to a real world solution or not?



It's probably worth mentioning that your code at lines 37 and 39 discards the line-ending characters from the text in the database. It's quite likely that you didn't want to do that.
 
Dave Tolls
Master Rancher
Posts: 4371
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not attaching a StringReader to a Clob.
You are passing it into the setClob method, which the JDBC driver then uses by reading from the reader and passing the contents to the database to put into the CLOB.

When you query the database and read out the row, you can access the Clob data through a few methods, one of which asks the Clob for a Reader to read the characters.
This is not the same Reader...it's just one the Clob creates and passes to you to allow you to stream the data from the CLOB on the database.
 
Robert Ingmarsson
Ranch Hand
Posts: 99
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, Mr. Tolls!

Thank you so much for your reply. I think I begin to understand now how the clob object works. Can you tell me if my method getClobData that I posted in the previous post of mine is the correct way to extract data from a clob via its stream or am I missing something?

Best wishes,
Robert!

 
Dave Tolls
Master Rancher
Posts: 4371
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, as Paul says, you'll lose any new line characters.
 
Robert Ingmarsson
Ranch Hand
Posts: 99
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, Mr. Tolls!

Could you be so kind to elaborate? I've read what Paul Clapham said about the line characters, but would like to see a proper working example similar to my method, getClobObject. I am writing this application as a material of a referential nature.

Best regards,
Robert!
 
Paul Clapham
Sheriff
Posts: 24754
59
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Robert Ingmarsson wrote:would like to see a proper working example



The readLine method reads the data up to the next line ending and returns that. It doesn't include the line ending, it just skips that.

To get all of the characters including line endings, simply read the characters one at a time from the BufferedReader and append them to the StringBuilder. It's a simple piece of code so I'm not going to post a "proper working example".
 
Robert Ingmarsson
Ranch Hand
Posts: 99
2
Netbeans IDE PHP Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, Mr. Clapham!

Did you mean something like this ?



I hope that was the correct procedure anyway, Any higher up in the hierarchy of interpretation and I'm totally lost.  

Best wishes,
Robert!


 
Paul Clapham
Sheriff
Posts: 24754
59
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, that's just fine.

Although I'm not convinced you need a BufferedReader to wrap the Reader you get from the Clob. And you already know the number of characters you're going to read, so you could simplify the loop a bit. But on the other hand that's a standard idiom for reading characters from a Reader so other people reading it will readily understand it.
 
Robert Ingmarsson
Ranch Hand
Posts: 99
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best, Mr. Clapham!

Thank you very much for your reply and guidance. Yes, I'll drop the BufferedReader. This thread is now solved  

Regards, Robert!
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!