Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing XML in the Database

 
Paul Grew
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 34375
346
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
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.
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact, designing your tables to withstand/evolve-to future modification will be the most recommended option.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic