473,651 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to store XML Document in MS SQL using JAVA

hi all
i am trying to store the XML Document object into MS SQL2005
i want to store this as whole not different tables;
plz help me regarding this i am trying form last two weeks i asked many
people but no use.
below is my program In that i want to store Document document object
into database which as var image/blob/clob plz help me


import javax.xml.parse rs.DocumentBuil der;
import javax.xml.parse rs.DocumentBuil derFactory;
import javax.xml.parse rs.FactoryConfi gurationError;
import javax.xml.parse rs.ParserConfig urationExceptio n;
import org.w3c.dom.Doc ument;
import org.w3c.dom.DOM Exception;
import org.w3c.dom.Ele ment;
import java.util.*;
import java.io.*;
import java.sql.*;
import java.io.File;
import java.io.FileNot FoundException;
import java.io.FileRea der;
import java.lang.Chara cter;
/*class input implements Serializable
{
byte[] toByteArray()
{
ByteArrayOutput Stream ob=new ByteArrayOutput Stream(100);
try
{
ObjectOutputStr eam oob=new ObjectOutputStr eam(ob);
oob.writeObject (this);
}catch(Exceptio n e)
{System.out.pri ntln("HeartBeat to Byte Conversion Error");}

if(len<0)
{
byte b[];
b=ob.toByteArra y();
len=b.length;
return b;
}
else return ob.toByteArray( );
}
}*/
class TestXml implements Serializable
{
public static String getFileData(byt e [] data) {
System.out.prin tln("\nIN GET FILE DATA");
String tmpString=null;
for (int i = 0; i < data.length; i++)
{
char c = Character.toCha rs(data[i])[0];
tmpString += c;
System.out.prin t(c);
}
return tmpString;
}
public static void main(String[] args) throws SQLException,IO Exception

{
// input in=new input();
org.w3c.dom.Doc ument document;
Document doc;
DocumentBuilder Factory factory =
DocumentBuilder Factory.newInst ance();
try {
DocumentBuilder builder = factory.newDocu mentBuilder();
document = builder.newDocu ment(); // Create from whole cloth
doc = builder.newDocu ment();
Element root =
(Element) document.create Element("rootEl ement");
document.append Child(root);
Element Child1 =
(Element) document.create Element("Child1 ");
Element Child2 =
(Element) document.create Element("Child2 ");
root.appendChil d( document.create TextNode("Some" ) );
root.appendChil d( document.create TextNode(" ") );
root.appendChil d( document.create TextNode("text" ) );

Child1.appendCh ild( document.create TextNode("Some" ) );
Child1.appendCh ild( document.create TextNode(" ") );
Child1.appendCh ild( document.create TextNode("text" ) );
Child2.appendCh ild( document.create TextNode("Some" ) );
Child2.appendCh ild( document.create TextNode(" ") );
Child2.appendCh ild( document.create TextNode("text" ) );
root.appendChil d(Child1);
root.appendChil d(Child2);
// System.out.prin tln(JDBCUtil.se rialize(documen t));
Foo f=new Foo();
ConnectionObjec t con=new ConnectionObjec t();
Connection co=con.GetConne ction();
Statement st = co.createStatem ent();
st.executeUpdat e("Insert into XML1
values('"+docum ent.getDocument Element()+"');" );
String str="Nataraju";
System.out.prin tln(str.getByte s());
Statement st1 = co.createStatem ent();
ResultSet rs=st1.executeQ uery("select * from XML1;");
Element root1;
while(rs.next() )
{
// BufferedReader br=new BufferedReader( rs.getAsciiStre am(1));
/* byte b1[]=(rs.getAsciiSt ream(1)).getByt es();
ByteArrayInputS tream b=new ByteArrayInputS tream(b1);
int c;
while((c=b.read ())!=-1)
{
System.out.prin t((char)c);
b.reset();
}*/
byte [] data = rs.getBytes(1);
String Str=getFileData (data);
System.out.prin tln(Str);

}

co.close();

}
catch (ParserConfigur ationException pce) {
// Parser with specified options can't be built
pce.printStackT race();

}
}
}

May 3 '06 #1
0 3245

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3843
by: Stefan Garde | last post by:
I need to figure out how you store a XML file (and its data) down in a Access database, by the help of SQL. I have tried looking through the net, but havent been very lucky (only found a course on how to do it, which was in america somewhere i think). I work in Java, so would be very happy if someone had some code example from that or a link. But anything is acceptable really. Hope to get some response
6
12972
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java scripts. Being a javascript newbie and after significant testing, I suspect that the document.write fails after finding a </script> within pageVar. Does a trick exist that enables one to slightly alter pageVar whereby enabling...
9
1915
by: F. Da Costa | last post by:
Hi, Does anybody know why IE5+ does *not* honour array objects (like a table) across a session? Example: Frame A contains a var tableVar which is set via form Frame B (on init) using top.A.tableVar = document.getElementById("someTable"); As long as Frame B is *not* 'refreshed/ reloaded' witk another page the
4
3295
by: Neil Cherry | last post by:
I've seen references to using <applets ... > and document.applets to access public Java functions from Javascript. Do I still use document.applets with <object ...>? BTW, the FAQS page seems to be broken. -- Linux Home Automation Neil Cherry ncherry@comcast.net http://home.comcast.net/~ncherry/ (Text only) http://hcs.sourceforge.net/ (HCS II)
1
3603
by: davo | last post by:
I've been puzzled by this one for ages. I've tried everything I can think of, and now it is time to ask for help. THE APPLICATION A J2EE application which reads an XML file from the /WEB-INF/xml directory within a Sun AppServer and transforms the XML via an XSLT into an HTML file that is served to the user's browser. THE PROBLEM I get a DOM Document from the following line, but when I return the Document from the class which creates it,...
2
7567
by: Marcin Cenkier | last post by:
Hi, I want to validate a DOM document, and if I build DOM from a stream using documentBuilder.parse() validation using validator.validate(DOMSource) works, but if I create the same document manually then validation throws an exception: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element ....
0
1855
by: rxding | last post by:
Hello, Performance reason we need to move some of our code into database. Java Store Procedure is given the first choice. However, while investigating some sample code of Java store procedure, PreparedStatement seems to be a must, such as PreparedStatement pstmt = conn.prepareStatement(sql); ..., pstmt.close() in the end. My question is that if the prepareStatement(sql) is called each time when the Java Store Procedure is called, will...
2
7839
by: Andy | last post by:
Hi, I have an XML document that uses namespaces (it is from a Word 2007 file). I want to retrieve all the "t" elements that belong to the "w" namespace (<w:t>) using XPath from VB.NET 2003 (.NET framework 1.1). I've successfully loaded the document into a XmlDocument DOM parser (I can dump the contents using OuterXML). And, I've created a XmlNamespaceManager and assigned it the "w" namespace.
10
8791
by: Simon Brooke | last post by:
The DOM API has included public Node importNode(Node,boolean) as a method of the Document interface for a long time. Does anything actually implement it? Xerces 2 is giving me: org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not support the requested type of object or operation. at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source) at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown Source)
0
8273
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8789
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8693
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7293
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6156
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4279
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2694
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.