File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Store array in database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Store array in database" Watch "Store array in database" New topic

Store array in database

Bill Hayes

Joined: Sep 24, 2007
Posts: 24
I need to store an array in an Oracle database. I'm not sure if I should be using blob or clob and more important, I have not been able to find an example of storing an array. Is this even possible?
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32815

An array of what? The data structure to store depends on what is in the array.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Bill Hayes

Joined: Sep 24, 2007
Posts: 24
I'll be storing an array of strings. I know I can simply store a delimted string in a regular varchar field then use StringTokenizer. But storing an array sounded interesting. If coding the storage of array is a really big effort I will probably go the StringTokenizer way. I just wanted to give it one last chance before giving up.
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
If you serialize the object then you can use a BLOB
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Oracle has support for collections. It's very much possible to store the array/collections. You have two options
1. Create new types in oracle and change your JDBC calls to use Oracle specific classes. This might be big effort based on your need.
2. Create new types in oracle and use stored procedure to do all DML and Select.

These links will help you
and other chapters in PL/SQL user guide
Consider Paul's rocket mass heater.
subject: Store array in database
It's not a secret anymore!