Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / August 2005

Tip: Looking for answers? Try searching our database.

openXML with JDBC

Thread view: 
Sandy - 11 Aug 2005 10:26 GMT
Hi,

I want to use the MS-Sqlserver's OPENXML function in my java application (to
load data from xml file into database)
I am using mssqlserver.jar (JDBC fro sqlserver by MS).
Can somebody tell me how do i execute the OPENXML function from JDBC.

Thanks
Dai Wei - 12 Aug 2005 02:59 GMT
Copy from:
http://www.jnetdirect.com/jsqlconnectTechDocs/Documentation/TechnicalReference.html

The following example shows how to build a JDBC result set from an XML
document using SQL Server's sp_xml_preparedocument procedure.

/* Parse the XML document and select the required columns */

String exec =
 "DECLARE @_hDoc int "+
 "EXEC sp_xml_preparedocument @_hDoc OUTPUT, "+
 "N'<ROOT> "+
 " <Customers CustomerID=\"Customer1\" ContactName=\"Joe\"
CompanyName=\"Company1\"> "+
 "     <Orders CustomerID=
\"Customer1\"OrderDate=\"2000-08-25T00:00:00\"/>" +
 "     <Orders CustomerID=\"Customer1\"
OrderDate=\"2000-10-03T00:00:00\"/> "+
 " </Customers> "+
 " <Customers CustomerID=\"Customer2\" ContactName=\"David\"
CompanyName=\"Company2\"> "+
 "     <Orders CustomerID=
\"Customer2\"OrderDate=\"2000-09-23T00:00:00\"/>" +
 " </Customers> "+
"</ROOT>'" +
 "SELECT * FROM OPENXML(@_hDoc, N'/ROOT/Customers/Orders') with
(CustomerID nchar(10) '../@_CustomerID', OrderDate datetime) " +
 "EXEC sp_xml_removedocument @_hdoc";

/* Retrieve and display the result set */

s = s.executeQuery(exec);
ResultSetMetaData md = rs.getMetaData();
while (rs.next()) {
 for (int i=0; i<md.getColumnCount(); i++)
   System.out.print(rs.getString(i+1)+" ");
 System.out.println();
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.