wood burning stoves*
The moose likes JDBC and the fly likes storing xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "storing xml" Watch "storing xml" New topic
Author

storing xml

joshua k
Greenhorn

Joined: Nov 03, 2000
Posts: 13
how do i store an xml string in a database the " and ' chars do
not allowing me to store
the xml string i've tried vaarchar2,clob,long raw none work
any suggestions will be welcome!!!
------------------
josh
[This message has been edited by joshua k (edited February 01, 2001).]


josh
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"joshua k",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Thanks.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Muhammad Ali
Greenhorn

Joined: Dec 04, 2000
Posts: 28
I am not an expert of the field. However, I faced the same situation and had to write an encoding function myself. It replaced all single or double quotation marks in a string with my own strings.
I mean you need a custom designed solution made by yourself. There is no other way out. Just my opinion.
Muhammad Ali Shah
Karachi.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Here are some suggestions -
a) Since ALL attribute values needs to be quoted, you can simply omit the quote while storing and put the quote while restoring.
b) Use some kind of a unique pattern( eg - #*quote*# ) while storing and replace it with the actual quote while retreiving.

------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
This is really more of a database question than one on XML, so I've moved it over. You may want to search the database forum to see if a solution has already been posted, too.
ram my
Greenhorn

Joined: Aug 25, 2003
Posts: 2
hi
In my application using dom Object i write an flat xml File,
i want to put xml contents inside the database
1)
can i store the xmlcontents directly into databse with out writing in
the Flat File
2)can i store the file as String inside the dataBase instead of
CLOB which is Better?
3)As Benoit said, can i go for JDBC 3.0 which Explictly
supportts all database without using SPecific Interface(ex:java.sql.CLOB)
4)is there anyway i can i store the File which should Explictly support all
databases.
Its Urgent ,plz Reply Soon....
Thanks
Ramesh Krishnan
rahul V kumar
Ranch Hand

Joined: May 20, 2003
Posts: 82
I have once written some sample code for this.
I was using LONG datatype of oracle to stored the XML Document.
From Java World
I was using setAsciiStream() method to send the XML Data
I am not sure dont know if thats the best way round.
But it works.
Lu Battist
Ranch Hand

Joined: Feb 17, 2003
Posts: 104
If you go with a varchar datatype where double quotes are acceptable and only single quotes give you a problem, then the trick is to parse it and replace all single quotes with two single quotes. Works for db2. See your database documentation - there is always some way to get quotes stored in there, its just a matter of finding the way your database allows it. I've also found that in using prepared statements, I don't have to deal with this issue anymore - it just handles it the right way. So you may want to give that a try.
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
USE A PREPARED STATEMENT. Example:

Then the database will deal with the string. The above uses an oracle sequnce, but I'll assume you can conform your code to this...
ram my
Greenhorn

Joined: Aug 25, 2003
Posts: 2
Thanks rahul,
Its working!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing xml
 
Similar Threads
How to create XML file programmatically?
Storing image in xml
storing xml
Running ant from java program with dynamic build.xml
How to sore Xml formatted string in a zippped string and store into memory ?