GeeCON Prague 2014*
The moose likes JDBC and the fly likes how to convert ArrayList<String>to sumthing that suite in sql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to convert ArrayList<String>to sumthing that suite in sql" Watch "how to convert ArrayList<String>to sumthing that suite in sql" New topic
Author

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

sk said
Greenhorn

Joined: Mar 30, 2011
Posts: 5
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

Joined: Mar 24, 2008
Posts: 3833

Welcome to CodeRanch, SK Said

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

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
sk said
Greenhorn

Joined: Mar 30, 2011
Posts: 5
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

Joined: Oct 27, 2005
Posts: 19697
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: how to convert ArrayList<String>to sumthing that suite in sql