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 Storing XML in the 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 "Storing XML in the Database" Watch "Storing XML in the Database" New topic

Storing XML in the Database

Paul Grew

Joined: Jul 18, 2011
Posts: 1
I am working on an application that will require storing xml in the database. The xml will contain user permissions that will be loaded into a POJO after the user logs in(Using JAXB). The permissions will be created/edited by the same application. We are using Oracle database. My question is what's the best way of storing XML in the database. Should I use XMLTYPE, or VARCHAR? Is there a better way to accomplish this. Thanks in advance for your advice.

P.S. The reason I am storing permissions in the XML because I want to be albe to add/change permissions without adding more columns to the permissions table.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32815

Welcome to CodeRanch!

An XML type is better than varchar. I don't follow you reason though. I understand not wanting to add columns, but you don't need to. What if you had a table permission_details with columns id, name and value? You'd just add a new row (name/value pair) for a given id and query directly. Managing security in the app is fine too, but you wouldn't need to add a column either way.

[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
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

In fact, designing your tables to withstand/evolve-to future modification will be the most recommended option.

Not many get the right opportunity !
I agree. Here's the link:
subject: Storing XML in the Database
It's not a secret anymore!