• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing a CLOB to the db

 
Joe Ridener
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception that was thrown was this


Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.sql.Clob
at database.Database_Practice_.main(Database_Practice_.java:50)

Line 50 that that exception is reffering to is this statement

ps.setObject(4, inputValues[3]);

The array inputValues is an Object array and index 3 that it refers to is a timestamp from java.util.Date().toString() wrapped in a java.sql.Timestamp object being treated generically as an object in the array.


Ill just copy the code so you can see it:



 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What type does the DB field "date_created" have?
 
Joe Ridener
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it uses a longtext in the db field
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like it's trying to convert the TimeStamp into a String, but then fails to convert it to a CLOB. Why are you using setObject(...) instead of the specific methods for the datatypes in question? That would eliminate some of the guesswork of the conversion process.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic