Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: Large XML Data, Parsing, JDBC, RMI, 2 Oracle DB

Re: Large XML Data, Parsing, JDBC, RMI, 2 Oracle DB

From: Raden Java <radenjava_at_theglobe.com.invalide>
Date: Sat, 21 Jul 2001 11:54:46 -0700
Message-ID: <tljjvk1abtt193@corp.supernews.com>

Hi, this is the parsing program. It doesn;t do any Thread yet. Can anyone suggest a better way to do it with thread ? Thanks again

import oracle.xml.parser.v2.*;

import oracle.jdbc.driver.*;

import java.io.*;
import java.net.*;
import java.util.*;
import java.util.Date;
import java.text.*;
import java.sql.*;
import java.rmi.*;

import javax.naming.*;
import javax.sql.*;

public class DataParsing implements XMLToken {

    static XMLTokenizer parser = null;
    static int num = 0, i = 0, count = 0;     static String rElement, thisElement, thisAtt, caseID, s;

    static StringBuffer sbuffer;
    static StringBuffer[] between = new StringBuffer[10];

    static Connection conn = null;
    static PreparedStatement pstmt = null;     static ResultSet rs = null;

    static PrintWriter debug;

    static DataInsert insertDB = null;
    //private Thread myThread;     

    static public void main(String[] args) throws IOException, Exception     {

        try
        {
            insertDB = (DataInsert)Naming.lookup(args[0]);
            doParse("file.xml");

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

    }
    /*
    public synchronized void start()
    {
        if(myThread == null)
        {
            myThread = new Thread(this);
            myThread.start();

}

    }*/
    // Initializing
    static void doParse(String arg) throws Exception {
        URL url = createURL(arg);
        parser  = new XMLTokenizer((XMLToken)new DataParsing());
        parser.setToken (STagName, true);
        parser.setToken (EmptyElemTag, true);
        parser.setToken (STag, true);
        parser.setToken (ETag, true);
        parser.setToken (ETagName, true);
        parser.setToken (Attribute, true);
        parser.setToken (AttName, true);
        parser.setToken (AttValue, true);
        parser.setToken (Reference, true);
        parser.setToken (Comment, true);
        parser.setToken (CharData, true);
        parser.setToken (CDSect, true);
        parser.setToken (PI, true);
        parser.setToken (PITarget, true);
        parser.setToken (XMLDecl, true);
        parser.setToken (TextDecl, true);
        parser.setToken (DTDName, true);
        parser.setToken (AttListDecl, true);
        parser.setToken (elementdecl, true);
        parser.setToken (ElemDeclName, true);
        parser.setToken (EntityDecl, true);
        parser.setToken (EntityDeclName, true);
        parser.setToken (EntityValue, true);
        parser.setToken (NotationDecl, true);
        parser.setToken (ExternalID, true);
        
        try {
            parser.tokenize (url);

} catch (SAXException e) {
//System.out.println (e.getMessage());
}

    }     

    // This is read by doParse(arg)
    public void token(int token, String value)     {

        switch (token) {
            case XMLToken.STagName:
                thisElement = value;    // set current element
                if(value.equals (rElement)) {
                    parser.setToken (Comment, false);
                    parser.setToken (CharData, false);
                    parser.setToken (CDSect, false);
                    parser.setToken (PI, false);
                }
                break;
            case XMLToken.ETagName:
                if(value.equals (rElement)){
                    parser.setToken (Comment, true);
                    parser.setToken (CharData, true);
                    parser.setToken (CDSect, true);
                    parser.setToken (PI, true);
                }
                break;
            case XMLToken.CharData:
                if (thisElement.equals("Title"))
                {
                    try
                        {
                            insertDB.Title(caseID,value);
                        }catch(SQLException sqle){
                            sqle.printStackTrace();
                        }catch(RemoteException rme){
                            rme.printStackTrace();
                        }
                }
                if (thisElement.equals("Description"))
                {
                    try{
                        insertDB.Description(caseID,value);
                    }catch(SQLException sqle){
                        sqle.printStackTrace();
                    }catch(RemoteException rme){
                        rme.printStackTrace();
                    }
                }
            case XMLToken.AttName:
                thisAtt = value;       // set current attribute
                break;
            case XMLToken.AttValue:
                sbuffer = new StringBuffer(value);
                s = new String(sbuffer.substring(1, sbuffer.length()-1));
                
                if(thisElement.equals("Case"))
                {
                    if(thisAtt.equals("ID"))
                    {
                        caseID = s;
                    }
                }
                break;
                default:
                    break;

}

    }     

    static public URL createURL(String fileName) {

        URL url = null;
        try {
            url = new URL(fileName);

} catch (MalformedURLException ex) {
File f = new File(fileName); try { String path = f.getAbsolutePath(); // This is a bunch of weird code that is required to // make a valid URL on the Windows platform, due // to inconsistencies in what getAbsolutePath returns. String fs = System.getProperty("file.separator"); if (fs.length() == 1) { char sep = fs.charAt(0); if (sep != '/') path = path.replace(sep, '/'); if (path.charAt(0) != '/') path = '/' + path; } path = "file://" + path; url = new URL(path); } catch (MalformedURLException e) { System.out.println("Cannot create url for:" + fileName); System.exit(0); }
}
return url;

    }  

}
©Ø

In article <tlilner8k3pd5d_at_corp.supernews.com>, "Raden Java" <radenjava_at_theglobe.com.invalide> wrote:

> Hi,
> 
> I'm trying to insert a large of data over 25,000,000 elements in xml
> format to 2 different Oracle Database on 2 different server.
> 
> I'm currently working on 4 machines, machine A 1 and 2 is a database
> running Oracle 9i, machine B is a parsing machine (8 CPU Solaris), and
> machine C is where the RMI Connection to Database.
> 
> What, I'm doing right now is I'm parsing every elements from the files
> using Oracle Parser and insert it to database using jdbc. But the
> program isn;t using all of the cpus because it's only capable to Parse
> and insert around 18,000 elements / hour, 432,000 elements in 1 day.
> So to parse all of data it will take around 57 days ? It should be
> something wrong here, but I don't have any clue on how to get through
> it.
> 
> My only thought is to modified the parsing program, to utilize the 8
> cpus resources.
> 
> Can someone guide me how to find resource in Parallelism, so the Parsing
> program will utilize the SMP.
> 
> Or if anyone have some advice on the best way to implement it, I really
> appreciate it.
> 
> Thanks
Received on Sat Jul 21 2001 - 13:54:46 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US