Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to convert ArrayList<String>to sumthing that suite in sql

 
sk said
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i got a problem on converting ArrayList<String>. Since i cant use the ArrayList in sql.

i want to update `result` column in sql using preparedStatement.since the `result` parameter is LongBlob.and ArrayList<String> result_list=[apple, mango, banana, orange, grape,]

i want to store all the list in result_list into `result`.means i have to convert and type map.but, i dont know how to do it.
Anyone knows how to do it?
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch, SK Said

Can you show us what you have done so far, and the error you get...?
 
sk said
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijitha Kumara wrote:Welcome to CodeRanch, SK Said

Can you show us what you have done so far, and the error you get...?


Thanks VK...

This is code dat ive done so far
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LongBlob means you can store any binary data in there. That includes serialized objects; you could get an OutputStream from the PreparedStatement, wrap that in an ObjectOutputStream, than write the ArrayList to that. Don't forget to close the ObjectOutputStream or the serialization footer won't be present.

One major drawback with this approach: if the class changes and you haven't prepared for that properly (e.g. with a fixed serialVersionUid field) you will get an exception when getting the data back from the database.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic