Java +XML (SAX) Parser for Oracle 8.1.5 EE
Hi there :)
I am looking java classes for SAX to parse XML. I cannot find a valid parser, cause after downloaded from Oracle XDK for java, when i try to load this calasses i get a messages that i alot of classes connot be resolved.
If somebody have valid classes on Ora 8.1.5 please send me mail.
Adam
Have i possibilities to using some javatypes in oracle java stored procedure if this class is not loaded into db?
Cause i would like to create a java stored procedure to parse and insert some data from xml. I was thinking to pass xml file name as a parameter to my java procedure.
I must use Oracle 8.1.5 with jdk 1.1.7, and the best parser for me is SAX.
Please help.
Have i possobilities to use class inside oracle, which are placed outside oracle?
Something like classpath, where can i modify value (but classpath inside oracle)?
Similar Messages
-
SAX Parser for Oracle 8.1.5
I need SAX parser - i want load this class into DB. Any ideas?
AdamHave i possibilities to using some javatypes in oracle java stored procedure if this class is not loaded into db?
Cause i would like to create a java stored procedure to parse and insert some data from xml. I was thinking to pass xml file name as a parameter to my java procedure.
I must use Oracle 8.1.5 with jdk 1.1.7, and the best parser for me is SAX.
Please help.
Have i possobilities to use class inside oracle, which are placed outside oracle?
Something like classpath, where can i modify value (but classpath inside oracle)? -
SAX Parser for Oracle 8.1.5 needed!!! Urgent
Please help.
If you know something please send me mail.
Regards
KailWould you tell us how your will use SAX parser?
-
Sax Parser for loading XML file
We have a requirment by which we need to load huge XMl file in our DB everyday.
THe XML file format is like --
<?xml version="1.0" encoding="UTF-8"?>
<root>
<emp>
<ename>aaa</ename>
<sal>3000</sal>
</emp>
<emp>
<ename>bbb</ename>
<sal>5000</sal>
</emp>
<dept>
<name>productiong</name>
<location>USA</location>
<dept>
I have written XMl SAX parser to load this file into DB -
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
import java.io.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.xml.sql.*;
import oracle.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;
import java.util.*;
public class test extends DefaultHandler
String thisElement="";
String table_name="";
String table_name_2="";
String sql="";
String value_clause="";
StringBuffer value_clauseBuffer;
String Insert_sql="";
int flag;
String columnNames="";
String questionmarks="";
static String conStr = "jdbc:oracle:thin:@abcd1234:1521:dss501";
static Connection conn;
String arrayValues[] = new String[30];
int j = 0;
int emptyElementFlag = 0;
public SurveyReader() throws SQLException, FileNotFoundException, IOException{
DBConnect("username", "password");
public static void DBConnect(String username, String password)
throws SQLException, FileNotFoundException, IOException {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection(conStr, username, password);
conn.setAutoCommit(true);
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
thisElement = qName;
if (thisElement!=table_name){
columnNames = columnNames + ", " + qName;
questionmarks = questionmarks +", " + "?";
emptyElementFlag =0;
public void characters(char[] ch, int start, int length)
throws SAXException {
if (thisElement !="root"){
if ((length == 0) && (thisElement !="") ){
table_name = thisElement;
sql = " Insert into "+ table_name +"(";
value_clause="";
value_clauseBuffer =null;
columnNames = "";
questionmarks ="";
j =0;
if ((length != 0) && (thisElement!="") && (thisElement!=table_name)){
emptyElementFlag = 1;
String s = new String(ch, start, length);
String newString = s.replaceAll("'", "''");
// String newString = s;
if (value_clauseBuffer== null){
value_clauseBuffer = new StringBuffer(newString);
else{
value_clauseBuffer.append(newString);
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
if (thisElement !="root"){
if ((!(value_clauseBuffer == null))||((emptyElementFlag ==0) && (qName !=table_name))) {
try{
//value_clauseBuffer.append("', '");
if (value_clauseBuffer == null){
arrayValues[j]="";
else{
arrayValues[j]=""+value_clauseBuffer;
j = j+1;
value_clauseBuffer = null;
emptyElementFlag =0;
}catch(Exception e){
System.err.println(e);
System.exit(2);
if (qName == table_name){
if (!(value_clauseBuffer == null)){
value_clause = "'"+value_clauseBuffer;
columnNames =columnNames.substring(1, columnNames.length());
int paramNumber = j;
questionmarks =questionmarks.substring(1, questionmarks.length());
sql = sql + columnNames + " ) values (" + questionmarks +"); ";
Insert_sql=Insert_sql + sql;
sql = "Begin "+sql + " End; ";
try{
PreparedStatement pstat = conn.prepareStatement(sql);
for (int i=0; i<=j-1; i++ ){
int k = i+1;
pstat.setObject(k, arrayValues);
ResultSet rset = pstat.executeQuery();
rset.close();
pstat.close();
catch (Exception e) {
System.err.println(e);
System.out.print("sql " + sql);
System.exit(1);
table_name_2 = table_name;
thisElement = "";
public static void main (String args[]) {
XMLReader xmlReader = null;
System.out.println("Time " + new java.util.Date());
try {
SAXParserFactory spfactory = SAXParserFactory.newInstance();
spfactory.setValidating(false);
SAXParser saxParser = spfactory.newSAXParser();
xmlReader = saxParser.getXMLReader();
xmlReader.setContentHandler(new SurveyReader());
xmlReader.setErrorHandler(new SurveyReader());
InputSource source = new InputSource("short.xml");
xmlReader.parse(source);
conn.close();
} catch (Exception e) {
System.err.println(e);
System.exit(1);
This parser takes 2 hours to laod file of size around 8MB.
ANy suggestions on improving performance of the parser.
ANy other approach I should be taking to load this file into DB.
We are using ORacle 9i DB with Character set UTF 8.
Thanks!String buf = (new String(ch, start, length)).trim();
if (thisElement != "root"){
if ((buf.length() == 0) && (thisElement !="") ){
It run ok!
Thanks 58871!
Now, i want to export oracle table to xml file like :
<?xml version="1.0" encoding="UTF-8"?>
<root>
<emp>
<ename>aaa</ename>
<sal>3000</sal>
</emp>
<emp>
<ename>bbb</ename>
<sal>5000</sal>
</emp>
</root>
Can SAX export to xml format?
Pham Thanh Tung -
Hi all,
I am newbie to xml. I am using SAX parser for parsing xml documents. I have to write a code which parses all types of xsd files(including which can contain inline , referenced or both). Can anyone help / guide me how to code a generic xsd parser??
Thanks in advance,An XSD file is an XML file, so you can parse it using sax.
See :
http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/2a_echo.html
http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/work/Echo02.java
See also:
http://www.oracle.com/technology/tech/xml/xdk/doc/production/java/doc/java/javadoc/oracle/xml/parser/schema/XMLSchema.html#getXMLSchemaNodeTable -
Trying to use XML SAX parser with JDK2 ...
Hi,
I'm pretty new to Java.
I'm trying to write and use java sample using XML SAX parser. I try with XP and XML4J.
Each time I compile it give me a error message like
"SAX01.java:23: unreported exception java.lang.Exception; must be caught or declared to be
thrown
(new SAX01()).countBooks();
^
Note: SAX01.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
1 error"
For what I found, it seems that "deprecated" mean usage of old classes or methods. What should I do ?
Wait for the XML parser to be rewrite ? ....
Thank's
Constant"SAX01.java:23: unreported exception
java.lang.Exception; must be caught or declared to be
thrown
(new SAX01()).countBooks();
^Do this
public static void main(String[] args) throws Exception {
or do this
try
first part of expression?(new SAX0()).countBooks();
catch(Exception ex)
System.out.println("problem "+ ex);
Note: SAX01.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
1 error"deprecation is just a warning if there are no errors elsewhere in your program it should compile fine, but if you want to find out how to change it do this:
javac YourClassName.java -deprecation
then look in the docs for an alternative. -
XML SAX parser that support LexicalHandler
Hello,
I'm looking for an XML SAX parser that support a LexicalHandler.
I have xml files that are not well formed, ie: (&, <, >, etc...) characters within tags and I need to ignore them.
Anyone have a link to some opensource library ??
Thanks,
SamirDon't waste your time. Using a LexicalHandler isn't going to help with parsing malformed XML. You should get the person who produced those files to replace them with correct XML.
PC² -
Link for JAVA homogenous system copy for oracle
hi
I am unable to find the document for JAVA homogenous system copy for Oracle for NW04 & NW04s
kindly find me the link
thx
regards
ShoebHi
Here you go...-
[JAVA Sytem Copy for ORACLE |https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/cd76e07d-0c01-0010-298d-f699863f2ce4]
Regards
Jhony -
Hi,
I am parsing XML using SAX parser and fill the values into the HashTable ( like Key value pair ).. so i can get the vaues for a particular key using hash get function.
For the following XML. There are 2 "subscriberNumber" attribute, one is under "sn:Subscriber" and the another is under "sn:SubscriberChange".
I can able to put this values in hash table and when i print the Hash table it is printing as sn:subscriberNumber=[1234567890, 1234567890] .. But how will i know which one is from "sn:Subscriber" and which is from "sn:SubscriberChange"
This is the XML :
<sn:SubscriberNotification>
<sn:notificationSubType>1120</sn:notificationSubType>
<sn:Subscriber>
<cng:PaymentType>PostPaid</cng:PaymentType>
<sn:subscriberNumber>1234567890</sn:subscriberNumber>
</sn:Subscriber>
<sn:SubscriberChange>
<sn:subscriberNumber>1234567890</sn:subscriberNumber>
</sn:SubscriberChange>
</sn:SubscriberNotification>
Any suggestion and pointers are really helpful
Thanks,
-Raj..Try something like this:
import java.util.Stack;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
class MyHandler extends DefaultHandler {
Stack openTags = new Stack();
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (qName.equals("sn:subscriberNumber")) {
String parentTag = (String)openTags.peek();
System.out.println("Parent tag of this <sn:subscriberNumber> is : <" + parentTag + ">");
openTags.push(qName);
public void endElement(String uri, String localName, String qName) throws SAXException {
openTags.pop();
}Regards -
Why are all the events in the XML SAX parser not activated?
Hi everyone,
I have written a mini server that parses XML files into SQL queries.
Below is a segment of my code;
try {
Class.forName( JDBC_DRIVER );
myConnection = DriverManager.getConnection( DATABASE_URL, "username", "password");
EventXMLParser myEXP = new EventXMLParser(directory, myConnection);
File[] xmlFiles = directory.listFiles();
for (File xmlFile : xmlFiles) {
myEXP.XMLtoDB(xmlFile);
outWriter.println("File:" + xmlFile.getName() + " DONE");
} catch (SQLException e) {
System.err.println("SQLException for establishing connection");
e.printStackTrace();
} catch (ClassNotFoundException e) {
System.err.println("CLASS NOT FOUND EXCEPTION HERE");
e.printStackTrace();
} catch (Exception e) {
System.err.println(e);
e.printStackTrace();
finally {
outWriter.println("PARSING COMPLETED");
outWriter.close();
}Where the constructor EventXMLParser constructs the following:
public EventXMLParser(File path, Connection connection) {
super();
try {
this.XMLpath = path;
this.db_connection = connection;
this.xr = XMLReaderFactory.createXMLReader();
this.XMLSAXhandler = new DefaultHandler(); //create a new own handler
this.xr.setContentHandler(XMLSAXhandler);
this.xr.setErrorHandler(XMLSAXhandler);
//System.out.println("DEBUG: db_connection is " + db_connection.toString());
catch (Exception e) {
System.out.println("Constructor Error!");
e.printStackTrace();
}Below are all my helper methods within EventXMLParser.java
public void XMLtoDB(String XMLpath) throws Exception {
try {
//Input
System.out.println("XMLpath is : " + XMLpath);
/*FileReader r = new FileReader(XMLpath); debug
InputSource in = new InputSource(r);
xr.parse(in);
xr.parse(XMLpath);
/* Note that while parsing, the end of each event, </event>
* will trigger sendSQL to execute the query on the database
catch (Exception e) {
throw new Exception("Error with XMLtoDB!! Exception: " + e);
public void sendSQL(Event event, Connection sql_connection) throws SQLException {
//JDBC part
try {
System.err.println("DEBUG sendSQL");
Statement sql_statement = sql_connection.createStatement();
ResultSet resultSet = sql_statement.executeQuery( event.toSQL() );
catch (SQLException e) {
e.printStackTrace();
/* Parsing XML
* From here onwards it's all designed for the SAX Parsing with different event calling methods
public void startDocument() {
System.err.println("Start Document");
public void endDocument() {
System.err.println("End Document");
public void startElement(String uri, String name, String qName, Attributes atts) {
CurrentElement= name;
System.out.println("This is parsing");
public void characters(char ch[], int start, int length) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
StringBuffer sb = new StringBuffer();
for (int i = start; i < start + length; i++)
sb.append(ch);
String content = sb.toString();
if (CurrentElement.equals("eid"))
temp.setEventID( (Integer.valueOf(content)).intValue() ) ;
else if (CurrentElement.equals("sd"))
temp.setShort_description(content);
else if (CurrentElement.equals("ld"))
temp.setLong_description(content);
else if ( (CurrentElement.equals("dt")))
temp.setDate_Time( formatter.parse(content, new ParsePosition(0)) );
else if (CurrentElement.equals("repeat"))
temp.setRepeat_pattern( (Integer.valueOf(content)).intValue() );
else if (CurrentElement.equals("valid"))
temp.setValid_period(content);
else if (CurrentElement.equals("status")) {
temp.setStatus( (Integer.valueOf(content)).intValue() );
else {}
public void endElement(String uri, String name, String qName) {
System.err.println("DEBUG" + temp.toString()); /*debug*/
if (name.equals("event")) {
try {
/*debug*/ temp.setUserID(1);
/*debug*/ System.err.println("DEBUG: " + temp.toString());
sendSQL(temp, db_connection);
//temp = new Event();
catch (SQLException e) {
System.err.println(e);
}//end catch
}//end try
Where event is a public class Event {
//fields
private int userID = 1; // = 1 only applies for testing
private int eventID;
private String short_description;
private String long_description;
private Date date_time = null;
private int repeat_pattern;
private String valid_period;
private int status; //1 for new, 0 for modification and -1 for delete
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//Constructors
//every event requires the following: userID eventID and short_Description
public Event(int uID, int eID, String shortDescrp) {
setUserID(uID);
setEventID(eID);
setShort_description(shortDescrp);
public Event(int uid, int eid, String sd,
String ld, Date d_t, int r_p, String v_p, int s) {
setUserID(uid);
setEventID(eid);
setShort_description(sd);
setLong_description(ld);
setDate_Time(d_t);
setRepeat_pattern(r_p);
setValid_period(v_p);
setStatus(s);
//set
public void setUserID (int x) { this.userID = x ;}
public void setEventID (int x) { this.eventID = x ;}
public void setShort_description (String x) { this.short_description = x ;}
public void setLong_description (String x) { this.long_description = x ;}
public void setDate_Time(Date x) { this.date_time = x ;}
public void setRepeat_pattern (int x) { this.repeat_pattern = x ;}
public void setValid_period (String x) { this.valid_period = x ;}
public void setStatus (int x) { this.status = x; }
//get
public int getUserID() { return this.userID;}
public int getEventID() { return this.eventID;}
public String getShort_description() { return this.short_description;}
public String getLong_description() { return this.long_description;}
public Date getDate_Time() { return this.date_time;}
public int getRepeat_pattern() { return this.repeat_pattern;}
public String getValid_period() { return this.valid_period;}
public int getStatus() { return this.status; }
//Event to SQL statements;
public String toSQL() {
StringBuffer sb = new StringBuffer();
///if ( status == 1) {
sb.append( "INSERT INTO events SET" );
sb.append( " userID = " + userID + ", ");
sb.append( "eventID = " + eventID + ", " );
sb.append( "short_description = " + "\'" + short_description + "\'" + ", "); //String
sb.append( "long_description = " + "\'" + long_description + "\'" + ", "); //String
sb.append( "date_time = " + "\'" + formatter.format(date_time) + "\'" + ", ");
sb.append( "repeat_pattern = " + repeat_pattern + ", " );
sb.append( "valid_period = " + "\'" + valid_period + "\'" ); //String
sb.append( ";");
//} else if ( status == 2) {
System.err.println(sb.toString());
return sb.toString();
} My question is: I have taken my SQL query generated by toSQL() method in events and it worked.
Here is the funny thing:
Everything is correct syntax wise: No complaints what soever
The mysql part works: Tested separately.
So I tend to think that the problem lies within the SAX parser. I have written SAX2 parsers on this machine before and they have worked too. I tried inserting println statements all over startElement endElement etc etc only to find out that the SAX parser did not call any of the methods that I overided!! Why is that so?
Can you guys spot where my SAX parser fails?I see.
I try to correct this problem by removing super();
so right now my code looks like this:
static Event temp = new Event(0, 0, "null", "null", new Date(), 0, "null", 0);
static String CurrentElement = null;
static File XMLpath;
static Connection db_connection;
static XMLReader xr;
static DefaultHandler XMLSAXhandler;
//Constructor, Build the SAX Parser
public EventXMLParser(File path, Connection connection) {
try {
this.XMLpath = path;
this.db_connection = connection;
this.xr = XMLReaderFactory.createXMLReader();
this.XMLSAXhandler = new DefaultHandler(); //create a new own handler
this.xr.setContentHandler(XMLSAXhandler);
this.xr.setErrorHandler(XMLSAXhandler);
//System.out.println("DEBUG: db_connection is " + db_connection.toString());
catch (Exception e) {
System.out.println("Constructor Error!");
e.printStackTrace();
}This time, I created a new instance of default handler() which can be referenced by as the objects's XMLSAXhandler. However, that did not solve the problem, why does the problem still persist?
Right now, there is only one instance of a default handler created. So why does all my parsing event functions still get ignored? -
For a long time on technet the
PL/SQL parser release notes have
said that they will be supporting
SAX in a future release. Is there
any idea of when this support may
materialize? Or is Java the only
option for a parser in the db for
the near future that can handle large
documents?
nullWhat would you want to use as the implementation of the SAX2 ContentHandler interface in PL/SQL? Stored procedure-based callbacks? Just curious how you would envision this working. Your input is valuable to our future thinking in this area. Most teams using PL/SQL that want to use SAX have written Java Stored Procedures that use SAX internally inside the stored procedure (written in Java) but are not doing the SAX parsing with PL/SQL-based callbacks.
-
Generate xml source file for Oracle Order Capture Print Quote
Hi,
I am new to xml and need to work on creating templates for Print Quote.
I am trying to generate the xml source file for which I enabled the report in system administrator and set the output to XML and assigned to Quoting Reports responsiblity. I then assigned XML Report Publisher to the same responsiblity.
I ran the report (Print Quote) and then I am trying to run the XML Report Publisher but I cannot get the request id in the list of values.
I am able to generate xml source file for other reports like Printed Purchase Order etc.,
The view output for the (Print Quote) report is as follows:
<?xml version="1.0" ?>
- <!-- Generated by Oracle Reports version 6.0.8.26.0
-->
<ASOPQTER />
How do I get the xml source file? Or are there seeded templates that I can use to create more templates? Any help would be appreciated. Thanks RaviHi, I am in the same position - did this issue ever ger resolved by anyone. I have done a few XMLP reports successfully now using the Word add-in, but customising the Quote output differs from other standard reports.
If you look at the data definition for Quote it is a 'dummy' definition and has no XML file attached. Does anyone know how I can get the XML format for the report output?
Also the template uses XSL-FO ?!?!?! rather than RTF - not sure how to work with this, the Oracle docs are not very helpful in this regard either.
Has anyone successfully managed to customise the Quote print report? Many thanks,
Roger -
Is There An XML Schema Parser From Oracle ?
Is XML parser available from oracle different from Xml Schema parser ? Is schema parser available at all ? Where can I download it ? I tried a brief search and could not find ?
Help appreciated.
Thanx
SooryaThank you. I got it. I am trying to validate against an existing schema. But it always enters the "XMLParseException" handler.
Could you direct me to the documents which gives some examples ? or a 3 lines to validate would be helpful.
Thanx again.
Soorya
null -
AGAIN - Needed SAX parser for java on Oracle 8.1.5
like in subject.
I load succesful sax2, but i need load more useful parser like from oracle or ibm.
But when i try i get a lot of errors like ORA-29534 (NullPointerOperation).
KailOnly XML Parser v2 release 2.0.2.7 from Oracle works in 8.1.5, and this release does not support SAX2 unfortunately.
-
Hello all,
I am trying Parsing XML thorugh SAX. Were to get SJXP.jar and parser.jar files on sun site
if any body have these files plz mail :[email protected]String buf = (new String(ch, start, length)).trim();
if (thisElement != "root"){
if ((buf.length() == 0) && (thisElement !="") ){
It run ok!
Thanks 58871!
Now, i want to export oracle table to xml file like :
<?xml version="1.0" encoding="UTF-8"?>
<root>
<emp>
<ename>aaa</ename>
<sal>3000</sal>
</emp>
<emp>
<ename>bbb</ename>
<sal>5000</sal>
</emp>
</root>
Can SAX export to xml format?
Pham Thanh Tung
Maybe you are looking for
-
More Guru Winners for February 2015 in the VB category and many others!
It's been a busy week that also saw the TECHNET WIKI SUMMIT 2015 Then we had the results for February's TechNet Guru competition ALSO posted! http://blogs.technet.com/b/wikininjas/archive/2015/03/19/technet-guru-february-2015.aspx Below is a summary
-
hi, While doing Goods receipt for subcontracting order, following error is coming Account 46811050 requires an assignment to a CO object. Whereas acct. 46811050 is subcontracting expense GL acct. Where i should enter cost centre this GL acct in MIGO
-
ITunes not using credit balance, charging card instead
My daughter was given a $100 iTunes Store credit when she bought her MBP last summer, but hasn't made any purchases since then. This month she gifted a couple apps in iTunes, which shows her $100.00 credit balance, but Apple charged the credit card o
-
Hi how to create invoice price more than grn price.which place settings available,plz help, Regards mohan
-
I would love to see how early Video iPod owners are using their units. ie..playback video onto LCD tv screens in their car....