This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 3816

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: 19649
    
  18

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to convert ArrayList<String>to sumthing that suite in sql
 
Similar Threads
How to Convert HQL to SQL Query
converting a mysql DATETIME (HH:mm:ss) to seconds
String array to arraylist
Problems in converting ArrayList to a Strin gArray
Help on Drop Down