LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-23-2005, 07:05 AM   #1
anirudh
Member
 
Registered: Aug 2004
Location: bangalore india
Posts: 50

Rep: Reputation: 15
Exclamation onverting database rrelational data into xml using java


hi
i have created this java program that converts a sql querry to xml but now i need to convert all the tables data into xml for a particular schema
i am not aware of the sql to do so can anyone help
my java code is as below

package oracle.xml.sample;

import java.sql.Connection;
import java.sql.DriverManager;
import oracle.xml.sql.query.OracleXMLQuery;
import oracle.xml.parser.v2.XMLSAXSerializer;
import java.io.OutputStream;
import java.io.FileOutputStream;

public class XSUSAXPrint
{
static public void main(String[] args)
{

Connection conn;

String username = "partition";
String password = "welcome1";
String thinConn = "jdbcracle:thin:@localhost:1521:anidb";

try
{
//Open a File
OutputStream out = new FileOutputStream("out.xml");

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn= DriverManager.getConnection(thinConn,username,password);

XMLSAXSerializer sample = new XMLSAXSerializer(out);

// init the OracleXMLQuery
OracleXMLQuery qry =
new OracleXMLQuery(conn,"select * from inventory");
qry.getXMLSAX(sample);
sample.flush();

}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}

is there anyother way to do this i have also tried to create a cursor to do this but it doesnot give out a result set so as to convert it into xml.
plz help
the code for the sql procedure is as follows

DECLARE

CURSOR tnameCursor IS
SELECT table_name
FROM user_tables
ORDER BY table_name;

myTableName VARCHAR2(30);
aSQLcmd VARCHAR2(222);

BEGIN

FOR aRecord IN tnameCursor LOOP

myTableName := aRecord.table_name;
aSQLcmd := select * from'||myTableName;
EXECUTE IMMEDIATE aSQLcmd;

END LOOP;

END;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML database with python? (I don't understand the circular logic) flamesrock Programming 10 12-23-2004 08:31 PM
experiences with embedded mysql? XML instead of a database? SerfurJ Programming 2 12-11-2004 08:06 AM
xquerry on oracle 10g xml database anirudh Programming 1 09-27-2004 07:50 AM
GuardDog not able to open the protocol database xml file Diode Linux - Software 1 04-20-2004 08:04 AM
MySQL: Importing a database from an XML file concoran General 0 09-08-2003 02:58 AM


All times are GMT -5. The time now is 07:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration