Solved

exporting retreived data on the selection of a tree node into an other table on button click

Posted on 2004-09-29
82
396 Views
Last Modified: 2008-01-09
Hi,

I am having a tree with three node and each node retreiveing data from a database table, for eg


1001(angnr)
        |
         10(ver number)
               |
               20( UA number)
1002(angnr)
       |
       10(ver number)
               |
                30(UA number)

When the user selects particular node and clicks the button, I would like to retreive related data in an xml format and send that data into an other table. Im able to retreive related data based on the user selection of node, but I am unable to send that data. Its giving me an error
>>>java.io.FileNotFoundException: <?xml version = '1.0'?>“
>>>The system cannot find the indicated path

Could anyone please conttribute to this, all contributions will be appreciatted.

Thanks.

my code:-
-----------------------

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // action code for button
       
DefaultMutableTreeNode nodeSelected = (DefaultMutableTreeNode)jTree1.getSelectionPath().getLastPathComponent();
TreeSelectionObject obj = (TreeSelectionObject) nodeSelected.getUserObject();
String angNumber = null;
if ( obj.getType() == TreeSelectionObject.ANGNR ) {    
         angNumber = obj.getNumber();
        System.out.println(obj);
                                                                                     }
      else if ( obj.getType() == TreeSelectionObject.VERNR ) {  
      System.out.println(obj);
               DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)nodeSelected.getParent();
                  obj = (TreeSelectionObject)parentNode.getUserObject();
                  angNumber = obj.getNumber();
                  System.out.println("parent"+obj);
                     }
                                           
       else if ( obj.getType() == TreeSelectionObject.UANR ) {
        System.out.println(obj);
                   DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)nodeSelected.getParent().getParent();
                  obj = (TreeSelectionObject)parentNode.getUserObject();
                  angNumber = obj.getNumber();  
                  System.out.println("parent"+obj);
                  
       //xml code//
      Connection conn;
              try
              {
                  DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());                      
                conn = DriverManager.getConnection ("");
          OracleXMLQuery qry = new OracleXMLQuery(conn, "select * from regdet WHERE ang_nr1 = '" + angNumber + "'");
                              
                              String sx = qry.getXMLString();
                              String tableName = "employeetestinsert";
                              String fileName = sx;
                                          try {
                                          OracleXMLSave save = new OracleXMLSave(conn, tableName);
                                          InputStream is = new FileInputStream(fileName);
                                                                                  int rowCount = save.insertXML(is);
                                is.close();
                                                  }
                                      catch (IOException e) {
                                             System.out.println(e);
                                                         
                                                           }
                              
                                }
                                
                          catch (SQLException e)
                                {
                                    e.printStackTrace();      
                                      System.out.println(e);
                                }


0
Comment
Question by:vihar123
  • 33
  • 27
  • 11
  • +2
82 Comments
 
LVL 35

Assisted Solution

by:girionis
girionis earned 100 total points
ID: 12177810
> >>>java.io.FileNotFoundException: <?xml version = '1.0'?>“
> >>>The system cannot find the indicated path

That's a weird error message and I believe it is related to the xml file itself. Can you piost the first few lines? Also try to change this:

<?xml version = '1.0'?>

to this:

<?xml version = "1.0"?>

and tell us what happens.

0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 12177813
>>I would like to retreive related data in an xml format and send that data into an other table.

How would that work - how do you decide what part(s) of the DOM would be included?
0
 
LVL 37

Accepted Solution

by:
zzynx earned 300 total points
ID: 12177816
You pass the content of your query

         qry.getXMLString();

as a filename

>> InputStream is = new FileInputStream(fileName);
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12177832
I suggest you to use even to specify the encoding

<?xml version="1.0" encoding="UTF-8"?>
0
 

Author Comment

by:vihar123
ID: 12177858
>>>That's a weird error message and I believe it is related to the xml file itself. Can you piost the first few lines? Also try to change this:

well the program is retreiving it into an xml format, and just this i want to send, i dont want to change anything in it

the entire output when im selecting a node and pressing a button is coming like this

----

parent0015,000<<<<<(node being selected and when button clicked)
java.io.FileNotFoundException: <?xml version = '1.0'?>
<ROWSET>
   <ROW num="1">
      <ANG_NR1>0015,000<\ANG_NR1>
      <PROD_BEZ1>Test-Eraslan Test-DB-Praktikanten<\PROD_BEZ1>
      <KUNDE_NR1>24<\KUNDE_NR1>
      <FAKTOR1>10<\FAKTOR1>
      <BASISPROJEKT1>1234<\BASISPROJEKT1>
      <VER_NR1>1<\VER_NR1>
      <VER_BESH1>Test Arun<\VER_BESH1>
      <GESC_JAHR1>2004<\GESC_JAHR1>
      <CURR1>EUR<\CURR1>
      <GES_KALK1>Arun<\GES_KALK1>
      <KALK_MEK1>Arun<\KALK_MEK1>
      <KALK_ELE1>Arun<\KALK_ELE1>
      <REF_NR1>0015<\REF_NR1>
   <\ROW>
   <ROW num="2">
      <ANG_NR1>0015,000<\ANG_NR1>
      <PROD_BEZ1>Test-Eraslan Test-DB-Praktikanten<\PROD_BEZ1>
      <KUNDE_NR1>24<\KUNDE_NR1>
      <FAKTOR1>10<\FAKTOR1>
      <BASISPROJEKT1>1234<\BASISPROJEKT1>
      <VER_NR1>2<\VER_NR1>
      <VER_BESH1>Test Arun<\VER_BESH1>
      <GESC_JAHR1>2004<\GESC_JAHR1>
      <CURR1>EUR<\CURR1>
      <GES_KALK1>Arun<\GES_KALK1>
      <KALK_MEK1>Arun<\KALK_MEK1>
      <KALK_ELE1>Arun<\KALK_ELE1>
      <REF_NR1> <\REF_NR1>
   <\ROW>
<\ROWSET>
 (The system cannot find the indicated path)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12177865
Did you already try

       int rowCount = save.insertXML(sx);    // omitting the use of InputStream
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12177876
Like I said I think the error is at this line:

>>      InputStream is = new FileInputStream(fileName);

It expects a filename as parameter and you pass it the XML content

Try

       int rowCount = save.insertXML(sx);    // omitting the use of InputStream



0
 
LVL 37

Expert Comment

by:zzynx
ID: 12177882
I mean like this:

                           String sx = qry.getXMLString();
                           String tableName = "employeetestinsert";
                           try {
                                     OracleXMLSave save = new OracleXMLSave(conn, tableName);
                                     int rowCount = save.insertXML(sx);
                           }
0
 
LVL 35

Expert Comment

by:girionis
ID: 12177888
zzynx is correct. You need to pass a filename there not the whole xml content. I think this si the same problem you had earlier.
0
 

Author Comment

by:vihar123
ID: 12177903
>>>Did you already try

       int rowCount = save.insertXML(sx);    // omitting the use of InputStream

its giving me many errors

oracle.xml.sql.OracleXMLSQLException:  ' java.sql.SQLException:  Ora-01400:  Do not insert from ZERO in ("ANSKA_TEST"."employeetestinsert"."emp_no") possible ' with the processing of ROW element 2.  All earlier XML lines changes were put back.  in XML document found.

at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:2286)
        at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1361)
        at gui5.jButton1ActionPerformed(gui5.java:540)
        at gui5.access$200(gui5.java:31)
        at gui5$3.actionPerformed(gui5.java:178)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
        at java.awt.Component.processMouseEvent(Component.java:5100)
        at java.awt.Component.processEvent(Component.java:4897)
        at java.awt.Container.processEvent(Container.java:1569)
        at java.awt.Component.dispatchEventImpl(Component.java:3615)
        at java.awt.Container.dispatchEventImpl(Container.java:1627)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
        at java.awt.Container.dispatchEventImpl(Container.java:1613)
        at java.awt.Window.dispatchEventImpl(Window.java:1606)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
0
 
LVL 35

Expert Comment

by:girionis
ID: 12177925
If you want to pass the xml string then you will have to create a Document and pass it as the argument insted fo the InputStream.

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(sx)));

You will also need to import javax.xml.parsers.*;

0
 
LVL 35

Expert Comment

by:girionis
ID: 12177927
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12177937
>> its giving me many errors
That's yet another problem. But at least the original is solved.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12177944
>> This is the exact same answer I gave you here
I already thought I had seen that before ;°)
0
 

Author Comment

by:vihar123
ID: 12177958
>>>>Document document = builder.parse(new InputSource(new StringReader(sx)));

its giving an error as cannot resolve sombol: class Document and class InoutSource
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12177972
javax.swing.text.Document
org.xml.sax.InputSource
0
 

Author Comment

by:vihar123
ID: 12177974
>>>>> its giving me many errors
That's yet another problem. But at least the original is solved.

i think the better way is to stick to the inputstream and save the retreived xml (sx) in some temp file and parse it and provide an overwrite funcionality....

or is there some better way, i think experience counts more.....:-)
0
 

Author Comment

by:vihar123
ID: 12178001
>>>javax.swing.text.Document
org.xml.sax.InputSource

giving the error as

incompatible types
found   : org.w3c.dom.Document
required: javax.swing.text.Document
                                                
javax.swing.text.Document document = builder.parse(new org.xml.sax.InputSource(new StringReader(sx)));
                                                                                                                  ^
1 error
0
 
LVL 35

Expert Comment

by:girionis
ID: 12178017
> javax.swing.text.Document documen

should also be a org.w3c.dom.Document
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178033
So:

import org.xml.sax.*;
import org.w3c.dom.*;
0
 

Author Comment

by:vihar123
ID: 12178065
i tried this and its giving me the same error as before, given below


try {
  OracleXMLSave save = new OracleXMLSave(conn, tableName);
 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = factory.newDocumentBuilder();
  Document document = builder.parse(new InputSource(new StringReader(sx)));
 int rowCount = save.insertXML(sx);

}
      catch (ParserConfigurationException e) {
           System.out.println(e);
                                                         
                       }
        catch (SAXException e) {
       System.out.println(e);
                                                         
         }
             catch (IOException e) {
       System.out.println(e);
         }
--------------------------------------------------------------

oracle.xml.sql.OracleXMLSQLException:  ' java.sql.SQLException:  Ora-01400:  Do not insert from ZERO in ("ANSKA_TEST"."employeetestinsert"."emp_no") possible ' with the processing of ROW element 2.  All earlier XML lines changes were put back. found in XML document.

 at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:2286)
        at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1361)
        at gui5.jButton1ActionPerformed(gui5.java:547)
        at gui5.access$200(gui5.java:35)
        at gui5$3.actionPerformed(gui5.java:182)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
        at java.awt.Component.processMouseEvent(Component.java:5100)
        at java.awt.Component.processEvent(Component.java:4897)
        at java.awt.Container.processEvent(Container.java:1569)
        at java.awt.Component.dispatchEventImpl(Component.java:3615)
        at java.awt.Container.dispatchEventImpl(Container.java:1627)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
        at java.awt.Container.dispatchEventImpl(Container.java:1613)
        at java.awt.Window.dispatchEventImpl(Window.java:1606)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
 
0
 
LVL 35

Expert Comment

by:girionis
ID: 12178077
Are you sure you are allowed to insert 0 (zero) in the column?
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12178095
>Ora-01400:  Do not insert from ZERO in ("ANSKA_TEST"."employeetestinsert"."emp_no") possible ' with the processing of ROW element 2.

if you can see the xml produced search in it ANSKA_TEST or employeetestinsert or emp_no. I believe the error is in the data you try to insert using xml.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12178102
the table is emplyeetestinsert and the column is emp_no. Probably you are inserting a value not agree with what type/value is declared in the OracleDB.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12178110
>...with the processing of ROW element 2.

So search the second row you try to insert in that table (llok at the particular column).
0
 

Author Comment

by:vihar123
ID: 12178272
when im saving this as an xml file and giving it as  a file name to the input stream, its inserting without any problem, so i think the problem is not with the table.....
can i save the retreived xml file temporarily and overwrite it all the time button has been clicked???
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178340
>> can i save the retreived xml file temporarily and overwrite it all the time button has been clicked???
Yes, no problem
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178357
You can do something like this

File theFile = new File("<your path to a temp file>");
if (theFile.exists())
   theFile.delete()

// Here, the file doesn't exist yet...
if ( theFile.createNewFile() ) { // ...and was successfully created
   theFile.deleteOnExit(); // make sure the temporary file is deleted when the application exits
   // Do your stuff
}
0
 

Author Comment

by:vihar123
ID: 12178457
when im trying like this its not accepting the path, its giving error as >>>illegal escape characters

-----------------
String sx = qry.getXMLString();
String tableName = "employeetestinsert";
String fileName = "temp.xml";
try {
OracleXMLSave save = new OracleXMLSave(conn, tableName);
File fileName = new File("I:\Gotla\java");
if (fileName.createNewFile() ) {
theFile.deleteOnExit();
 }
if (fileName.exist())
fileName.delete();

InputStream is = new FileInputStream(fileName);
 int rowCount = save.insertXML(sx);
is.close();
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178476
Make that

   File file = new File("I:/Gotla/java/temp.xml");
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178478
1) "file" instead of "fileName" since fileName is already used
2) forward slashed instead of backslashes
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178492
>> String sx = qry.getXMLString();
>> String tableName = "employeetestinsert";
>> String fileName = "temp.xml";
>> try {
>>     OracleXMLSave save = new OracleXMLSave(conn, tableName);
>>     File fileName = new File("I:\Gotla\java");                                          /// <<<<<<< here you reuse the variable "fileName"
>>     if (fileName.createNewFile() ) {
>>        theFile.deleteOnExit();
>>         }
>>     if (fileName.exist())
>>              fileName.delete();

>>      InputStream is = new FileInputStream(fileName);
>>      int rowCount = save.insertXML(sx);                     /// <<<<<<<<<<< Aren't you supposed to use the file here??
>>         is.close();
>>  }
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178505
String sx = qry.getXMLString();
String tableName = "employeetestinsert";
String fileName = "I:/Gotla/java/temp.xml";
try {
      OracleXMLSave save = new OracleXMLSave(conn, tableName);
      File theFile = new File(fileName);
      if (theFile.exist())                              // <<<<<< First delete it if it exists from another get/send action
        theFile.delete();
      if (theFile.createNewFile() )              // <<<<<<< now create it
         theFile.deleteOnExit();

      InputStream is = new FileInputStream(theFile);
      int rowCount = save.insertXML(theFile);                      // <<<<<<<<<< not sure
      is.close();
}
0
 

Author Comment

by:vihar123
ID: 12178537
its giving me an exception as file not found, i think something is wrong in this code, can u please make the needed changes, thanks.


String sx = qry.getXMLString();
String tableName = "employeetestinsert";
String fileName = "temp.xml";
try {
 OracleXMLSave save = new OracleXMLSave(conn, tableName);
 InputStream is = new FileInputStream(fileName);
 File file = new File("I:/Gotla/java/temp.xml");
 if (file.createNewFile() ) {
file.deleteOnExit();
    }
if (file.exists())
file.delete();

int rowCount = save.insertXML(sx);
System.out.println("successfully created");
is.close();
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178545
Of course drive I: won't exist on all systems on which you run this program, therefor maybe you better use

       File.createTempFile()

This way, you're also get rid of the problem of already existing files.


String sx = qry.getXMLString();
String tableName = "employeetestinsert";
try {
      OracleXMLSave save = new OracleXMLSave(conn, tableName);
      File theFile = File.createTempFile("myApp", "xml");
      theFile.deleteOnExit();

      // use theFile
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178560
>> its giving me an exception as file not found

Of course! You have:

String fileName = "temp.xml";
...
InputStream is = new FileInputStream(fileName);     // <<<< here, the file "temp.xml" doesn't exists yet

Use the code of my last post.
0
 

Author Comment

by:vihar123
ID: 12178609
its giving me error:-
cannot resolve symbol
symbol  : method insertXML (java.io.File)
location: class oracle.xml.sql.dml.OracleXMLSave
int rowCount = save.insertXML(theFile);
----------------------------------

try {
OracleXMLSave save = new OracleXMLSave(conn, tableName);
File theFile = new File(fileName);
if (theFile.exists())
theFile.delete();
if (theFile.createNewFile() )                                                   theFile.deleteOnExit();

InputStream is = new FileInputStream(theFile);
      int rowCount = save.insertXML(theFile);                                                                is.close();
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178632
If you wrote this:

>> when im saving this as an xml file and giving it as a file name to the input stream, its inserting without any problem
(btw, have you checked that it was really written correct to the database?)

what code did you have?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178641
>> its giving me error:-
>> cannot resolve symbol symbol  : method insertXML (java.io.File)

These are the possible usages:

 int insertXML(org.w3c.dom.Document doc)
 int insertXML(java.io.InputStream xmlStream)    // Think you probably need this one
 int insertXML(java.io.Reader xmlStream)
 int insertXML(java.lang.String xmlDoc)
 int insertXML(java.net.URL url)  
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178657
Don't solve the error by just writing

      InputStream is = new FileInputStream(theFile);
      int rowCount = save.insertXML(is); // <<<<<<<<<<< the file is still empty at this stage

That's why I asked:
>> what code did you have?
0
 

Author Comment

by:vihar123
ID: 12178670
>>>what code did you have?

i saved the retreived xml as emps.xml and put it in the I drive and its exactly filling the table......


----

import java.sql.*;
import java.math.*;
import oracle.xml.sql.query.*;
import oracle.jdbc.*;
import oracle.jdbc.driver.*;
import oracle.xml.sql.dml.*;
import oracle.xml.sql.*;
import java.net.*;
import oracle.xml.parser.v2.*;
import java.io.*;
import oracle.xml.sql.dml.OracleXMLSave;
import oracle.sql.CLOB.*;


public class testxml2
{
    public static void main(String args[]) throws SQLException
    {
       
        Connection conn;
       
 try
{
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
                     
 conn = DriverManager.getConnection ("");
                       
OracleXMLQuery qry = new OracleXMLQuery(conn, "select * from emp1");
("java.class.path") );

String sx = qry.getXMLString();
String tableName = "employeetestinsert";
String fileName = "emps.xml";
                              
                                                           
try {
 OracleXMLSave save = new OracleXMLSave(conn, tableName);
InputStream is = new FileInputStream(fileName);
int rowCount = save.insertXML(is);
is.close();
                                          
System.out.println("Inserted successfully" + "  " + "*"+ rowCount +"*"+ "  " + "rows into" + "  " + tableName);      
                                }
catch (IOException e) {
System.out.println(e);
                                                         
  }
                    
                                }
                             catch (SQLException e)
                                         {
                                          e.printStackTrace();      
                                      
                                          System.out.println(e);
                                          
                                         }
       
    }
}      
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 37

Expert Comment

by:zzynx
ID: 12178723
>> i saved the retreived xml as emps.xml and put it in the I drive and its exactly filling the table......
All right.

      // 1) Create the temporary file as stated above

      // 2) Save the retreived xml in the temporary file created (instead of emps.xml)

      // 3) then use it:
      InputStream is = new FileInputStream(theFile);
      int rowCount = save.insertXML(is);
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178729
I think now you have all components. Just have to stick them together ;°)
0
 

Author Comment

by:vihar123
ID: 12178765
>>>// 1) Create the temporary file as stated above

i saved it manually and stored it
well thats what my question was how to save the retreived file and also overwrite it
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178858
>> well thats what my question was how to save the retreived file and also overwrite it
And that after 45 comments in this thread! Phew...
0
 

Author Comment

by:vihar123
ID: 12178886
>>>can i save the retreived xml file temporarily and overwrite it all the time button has been clicked???

i think i asked much before :-))
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12178897
Well, I suppose you have the xml content in a String object:

import java.io.*;

// 1) Create the temporary file as stated above

// 2)

try {
        BufferedWriter out = new BufferedWriter(new FileWriter(theFile));      // <<<<<< theFile being the File object representing the temporary file
        out.write(yourXMLContent);        //<<<<<< your String
        out.flush();
        out.close();
} catch (IOException e) {
}
0
 

Author Comment

by:vihar123
ID: 12179079
>>>its again giving me the same error....its nicely creating the xml file but when inserting giving me this error.


try {
 OracleXMLSave save = new OracleXMLSave(conn, tableName);
                                                
File theFile = new File(fileName);
if (theFile.exists())
theFile.delete();
if (theFile.createNewFile() )                                                   theFile.deleteOnExit();
               try {
              BufferedWriter out = new BufferedWriter(new FileWriter(theFile));                                     out.write(sx);
                out.flush();
              out.close();
                                                                  } catch (IOException e) {
                                                                        }

       InputStream is = new FileInputStream(fileName);
            int rowCount = save.insertXML(is);              
            is.close();
                                                
                                    }
                                      catch (IOException e) {
                                             System.out.println(e);
                                                         
                                                           }
                              
                                   
                                }
                          catch (SQLException e)
                                {
                                    e.printStackTrace();      
                                      System.out.println(e);
                                }
                                                                                                                          
                                                                                                                   
                                                                                                                     }
       
                                                                                                             }
       

------------------------------------


oracle.xml.sql.OracleXMLSQLException:  ' java.sql.SQLException:  Ora-01400:  Do not insert from ZERO in ("ANSKA_TEST"."employeetestinsert"."emp_no") possible ' with the processing of ROW element 2.  All earlier XML lines changes were put back.  in XML document found.


at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:2317)
        at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1385)
        at gui5.jButton1ActionPerformed(gui5.java:564)
        at gui5.access$200(gui5.java:35)
        at gui5$3.actionPerformed(gui5.java:182)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
        at java.awt.Component.processMouseEvent(Component.java:5100)
        at java.awt.Component.processEvent(Component.java:4897)
        at java.awt.Container.processEvent(Container.java:1569)
        at java.awt.Component.dispatchEventImpl(Component.java:3615)
        at java.awt.Container.dispatchEventImpl(Container.java:1627)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
        at java.awt.Container.dispatchEventImpl(Container.java:1613)
        at java.awt.Window.dispatchEventImpl(Window.java:1606)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12179137
Replace
>> InputStream is = new FileInputStream(fileName);
by
     InputStream is = new FileInputStream(theFile);

0
 
LVL 37

Expert Comment

by:zzynx
ID: 12179244
Comment out some code so you just keep the saving of the XML content to a temporary file.
Compare the content of that file with the one you saved manually.
Do you see any differences? (length, content, ...)

If they are equal, it should work like with the manually saved file.
0
 

Author Comment

by:vihar123
ID: 12179245
ok i could find out the reason, its not accepting values that are starting with 0, so how can i make my table accept values starting with 0. i want to create a new table and then give it in my prg to populate it
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12179285
>> ok i could find out the reason, its not accepting values that are starting with 0
Then how come that importing the manually saved file worked correctly?
0
 

Author Comment

by:vihar123
ID: 12179334
>>>Then how come that importing the manually saved file worked correctly?

there im accessing an other table that has no values starting with 0
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12179409
>> there im accessing an other table that has no values starting with 0
If your goal is to find a problem as quickly as possible, it's no good idea to compare your app's behaviour on different input data...
0
 

Author Comment

by:vihar123
ID: 12179508
actually i was accessing a table that didnt had the structure of the retreived xml data, now i have created a new table with the same schema, its running but the strange thing is its not showing any values in the table, its showing as inserted 2 rows, but when im giving the select query, its not showing any values, but there are two rows being created,  and even the temp.xml is not found in the drive, i dont know why its not creating the temp.xml file

...............

String sx = qry.getXMLString();
String tableName = "xins";
                            
String fileName =  "I:/Gotla/java/temp.xml";
                                
 try {
OracleXMLSave save = new OracleXMLSave(conn, tableName);
File theFile = new File(fileName);
if (theFile.exists())
theFile.delete();
if (theFile.createNewFile() )                                                       theFile.deleteOnExit();
               System.out.println("file created successfully");
               try {
              BufferedWriter out = new BufferedWriter(new FileWriter(theFile));    
            out.write(sx);                                                        
              out.flush();
              out.close();
                                                                  } catch (IOException e) {
                                                                        }

       InputStream is = new FileInputStream(theFile);
            int rowCount = save.insertXML(is);              
            is.close();
                                                
                                    }
                                      catch (IOException e) {
                                             System.out.println(e);
                                                         
                                                           }
                              
                                   
                                }
                          catch (SQLException e)
                                {
                                    e.printStackTrace();      
                                      System.out.println(e);
                                }
                                                                                                                          
                                                                                                                   
                                                                                                                     }
       
                                                                                                             }
0
 

Author Comment

by:vihar123
ID: 12179605
oops sorry its creating xml file, actually i gave delete file on exit.......#

but the strange thing is that the prg is running, but its not doing its job...i dont understand why its just inserting two rows and not showing the values
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12179632
>> i dont understand why its just inserting two rows and not showing the values
Me neither. Sorry.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12179646
Did it show the values when you imported the manually create file?
0
 

Author Comment

by:vihar123
ID: 12179696
>>>Did it show the values when you imported the manually create file?

yes ofcourse

this is the emps.xml thats runinng successfully

<?xml version = '1.0'?>
<ROWSET>
   <ROW num="1">
      <EMP_NAME>Zdena</EMP_NAME>
      <EMP_NO>1015</EMP_NO>
      <EMP_DESIG>Project Manager</EMP_DESIG>
      <EMP_DEPT>EDPT</EMP_DEPT>
      <EMP_SAL>10000</EMP_SAL>
      <EMP_COMM>70</EMP_COMM>
      <EMP_LOC>fe</EMP_LOC>
   </ROW>
   <ROW num="2">
      <EMP_NAME>John</EMP_NAME>
      <EMP_NO>1001</EMP_NO>
      <EMP_DESIG>Manager</EMP_DESIG>
      <EMP_DEPT>Finance 1</EMP_DEPT>
      <EMP_SAL>5000</EMP_SAL>
      <EMP_COMM>50</EMP_COMM>
      <EMP_LOC>fe</EMP_LOC>
   </ROW>
   <ROW num="3">
      <EMP_NAME>Christian</EMP_NAME>
      <EMP_NO>1002</EMP_NO>
      <EMP_DESIG>Manager</EMP_DESIG>
      <EMP_DEPT>Personal 1</EMP_DEPT>
      <EMP_SAL>7000</EMP_SAL>
      <EMP_COMM>20</EMP_COMM>
      <EMP_LOC>fe</EMP_LOC>
   </ROW>
   <ROW num="4">
      <EMP_NAME>Markus</EMP_NAME>
      <EMP_NO>1003</EMP_NO>
      <EMP_DESIG>DBA</EMP_DESIG>
      <EMP_DEPT>Sales 1</EMP_DEPT>
      <EMP_SAL>4000</EMP_SAL>
      <EMP_COMM>34</EMP_COMM>
      <EMP_LOC>fe</EMP_LOC>
   </ROW>
   <ROW num="5">
      <EMP_NAME>Kajin</EMP_NAME>
      <EMP_NO>1004</EMP_NO>
      <EMP_DESIG>Distributor</EMP_DESIG>
      <EMP_DEPT>Dist 1</EMP_DEPT>
      <EMP_SAL>5000</EMP_SAL>
      <EMP_COMM>25</EMP_COMM>
      <EMP_LOC>fe</EMP_LOC>
   </ROW>
   <ROW num="6">
      <EMP_NAME>Stephen</EMP_NAME>
      <EMP_NO>1005</EMP_NO>
      <EMP_DESIG>HW Manager</EMP_DESIG>
      <EMP_DEPT>Hardware 1</EMP_DEPT>
      <EMP_SAL>8000</EMP_SAL>
      <EMP_COMM>25</EMP_COMM>
      <EMP_LOC>fe</EMP_LOC>
   </ROW>
   <ROW num="7">
      <EMP_NAME>Muller</EMP_NAME>
      <EMP_NO>1006</EMP_NO>
      <EMP_DESIG>HW Specilaist</EMP_DESIG>
      <EMP_DEPT>Hardware 2</EMP_DEPT>
      <EMP_SAL>2500</EMP_SAL>
      <EMP_COMM>25</EMP_COMM>
      <EMP_LOC>fe</EMP_LOC>
   </ROW>
   <ROW num="8">
      <EMP_NAME>Arun</EMP_NAME>
      <EMP_NO>1007</EMP_NO>
      <EMP_DESIG>Programmer</EMP_DESIG>
      <EMP_DEPT>Software 1</EMP_DEPT>
      <EMP_SAL>4000</EMP_SAL>
      <EMP_COMM>24</EMP_COMM>
      <EMP_LOC>fe</EMP_LOC>
   </ROW>
   <ROW num="9">
      <EMP_NAME>Meng</EMP_NAME>
      <EMP_NO>1017</EMP_NO>
      <EMP_DESIG>Trainee</EMP_DESIG>
      <EMP_DEPT>Const</EMP_DEPT>
      <EMP_SAL>4000</EMP_SAL>
      <EMP_COMM>50</EMP_COMM>
      <EMP_LOC>fe</EMP_LOC>
   </ROW>
   <ROW num="10">
      <EMP_NAME>Jia uei</EMP_NAME>
      <EMP_NO>1011</EMP_NO>
      <EMP_DESIG>Trainee#</EMP_DESIG>
      <EMP_DEPT>Construction</EMP_DEPT>
      <EMP_SAL>4000</EMP_SAL>
      <EMP_COMM>50</EMP_COMM>
      <EMP_LOC>se</EMP_LOC>
   </ROW>
   <ROW num="11">
      <EMP_NAME>Effah</EMP_NAME>
      <EMP_NO>1012</EMP_NO>
      <EMP_DESIG>Researcher</EMP_DESIG>
      <EMP_DEPT>Research</EMP_DEPT>
      <EMP_SAL>5000</EMP_SAL>
      <EMP_COMM>20</EMP_COMM>
      <EMP_LOC>AF</EMP_LOC>
   </ROW>
   <ROW num="12">
      <EMP_NAME>Johannes</EMP_NAME>
      <EMP_NO>1014</EMP_NO>
      <EMP_DESIG>Technician</EMP_DESIG>
      <EMP_DEPT>TE</EMP_DEPT>
      <EMP_SAL>4500</EMP_SAL>
      <EMP_LOC>LA</EMP_LOC>
   </ROW>
</ROWSET>

-------
this is the temp.xml, which is not showing any values

<?xml version = '1.0'?>
<ROWSET>
   <ROW num="1">
      <ANG_NR1>0015,000</ANG_NR1>
      <PROD_BEZ1>Test-Eraslan Test-DB-Praktikanten</PROD_BEZ1>
      <KUNDE_NR1>24</KUNDE_NR1>
      <FAKTOR1>10</FAKTOR1>
      <BASISPROJEKT1>1234</BASISPROJEKT1>
      <VER_NR1>1</VER_NR1>
      <VER_BESH1>Test Arun</VER_BESH1>
      <GESC_JAHR1>2004</GESC_JAHR1>
      <CURR1>EUR</CURR1>
      <GES_KALK1>Arun</GES_KALK1>
      <KALK_MEK1>Arun</KALK_MEK1>
      <KALK_ELE1>Arun</KALK_ELE1>
      <REF_NR1>0015</REF_NR1>
   </ROW>
   <ROW num="2">
      <ANG_NR1>0015,000</ANG_NR1>
      <PROD_BEZ1>Test-Eraslan Test-DB-Praktikanten</PROD_BEZ1>
      <KUNDE_NR1>24</KUNDE_NR1>
      <FAKTOR1>10</FAKTOR1>
      <BASISPROJEKT1>1234</BASISPROJEKT1>
      <VER_NR1>2</VER_NR1>
      <VER_BESH1>Test Arun</VER_BESH1>
      <GESC_JAHR1>2004</GESC_JAHR1>
      <CURR1>EUR</CURR1>
      <GES_KALK1>Arun</GES_KALK1>
      <KALK_MEK1>Arun</KALK_MEK1>
      <KALK_ELE1>Arun</KALK_ELE1>
      <REF_NR1> </REF_NR1>
   </ROW>
</ROWSET>

0
 

Author Comment

by:vihar123
ID: 12179725
the schema of the table looks like this............


CREATE TABLE xins (
  angnr1test        VARCHAR2(2040) NULL,
  projnr1test       VARCHAR2(2040) NULL,
  prodbez1test      VARCHAR2(2040) NULL,
  kundenr1test      VARCHAR2(2040) NULL,
  faktor1test       VARCHAR2(2040) NULL,
  basisprojekt1test VARCHAR2(2040) NULL,
  vernr1test        VARCHAR2(2040) NULL,
  verbesh1test      VARCHAR2(2040) NULL,
  gescjahr1test     VARCHAR2(2040) NULL,
  curr1test         VARCHAR2(2040) NULL,
  geskalk1test      VARCHAR2(2040) NULL,
  kalkmek1test      VARCHAR2(2040) NULL,
  kalkele1test      VARCHAR2(2040) NULL,
  refnr1test        VARCHAR2(2040) NULL
)
  PCTUSED    0
/
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12179738
That certainly looks rather different from:

<ROWSET>
   <ROW num="1">
      <ANG_NR1>0015,000<\ANG_NR1>
      <PROD_BEZ1>Test-Eraslan Test-DB-Praktikanten<\PROD_BEZ1>
      <KUNDE_NR1>24<\KUNDE_NR1>
      <FAKTOR1>10<\FAKTOR1>
      <BASISPROJEKT1>1234<\BASISPROJEKT1>
      <VER_NR1>1<\VER_NR1>
      <VER_BESH1>Test Arun<\VER_BESH1>
      <GESC_JAHR1>2004<\GESC_JAHR1>
      <CURR1>EUR<\CURR1>
      <GES_KALK1>Arun<\GES_KALK1>
      <KALK_MEK1>Arun<\KALK_MEK1>
      <KALK_ELE1>Arun<\KALK_ELE1>
      <REF_NR1>0015<\REF_NR1>
   <\ROW>
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12179768
And you think the problem is with

         <ANG_NR1>0015,000<\ANG_NR1>          // <<<<< this starting with '0'? I don't think that should be a problem.
0
 

Author Comment

by:vihar123
ID: 12179790
>>>That certainly looks rather different from:

ya but i think it doesnt make any diff, the entire structure is same i think....and when given varchar1(2040), it shld take in the values
0
 

Author Comment

by:vihar123
ID: 12179807
>>>And you think the problem is with

         <ANG_NR1>0015,000<\ANG_NR1>          // <<<<< this starting with '0'? I don't think that should be a problem.

me neither, if it is, the prg shld give run time error, but its running smoothly, but when iam coming to my db and checking the table, there are just two blank rows........
i dont know if its the prg fault or the table fault or something else
0
 
LVL 35

Expert Comment

by:girionis
ID: 12188002
>  <ANG_NR1>0015,000<\ANG_NR1>

Shouldn't this be:

<ANG_NR1>0015,000</ANG_NR1>
0
 
LVL 35

Expert Comment

by:girionis
ID: 12188006
... or in fact your whole xml file. You are using the opposite slash, \ instead of /.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12188038
What is the full excetion it gaves now?
0
 

Author Comment

by:vihar123
ID: 12188231
>>>or in fact your whole xml file. You are using the opposite slash, \ instead of /.

this is the xml file that is being retreived, its not giving any exception, just not showing any values........


<?xml version = '1.0'?>
<ROWSET>
   <ROW num="1">
      <ANG_NR1>0015.000</ANG_NR1>
      <PROD_BEZ1>Test-Eraslan Test-DB-Praktikanten</PROD_BEZ1>
      <KUNDE_NR1>24</KUNDE_NR1>
      <FAKTOR1>1.08</FAKTOR1>
      <BASISPROJEKT1>1234</BASISPROJEKT1>
      <VER_NR1>1</VER_NR1>
      <VER_BESH1>test eraslan test-db Praktikanten</VER_BESH1>
      <GESC_JAHR1>2004</GESC_JAHR1>
      <CURR1>EUR</CURR1>
      <GES_KALK1>Schlegel</GES_KALK1>
      <KALK_MEK1>Schlegel</KALK_MEK1>
      <KALK_ELE1>Schlegel</KALK_ELE1>
      <REF_NR1>1219.001</REF_NR1>
   </ROW>
   <ROW num="2">
      <ANG_NR1>0015.000</ANG_NR1>
      <PROD_BEZ1>Test-Eraslan Test-DB-Praktikanten</PROD_BEZ1>
      <KUNDE_NR1>24</KUNDE_NR1>
      <FAKTOR1>1.08</FAKTOR1>
      <BASISPROJEKT1>1234</BASISPROJEKT1>
      <VER_NR1>2</VER_NR1>
      <VER_BESH1>Test Arun</VER_BESH1>
      <GESC_JAHR1>2004</GESC_JAHR1>
      <CURR1>EUR</CURR1>
      <KALK_MEK1>Arun</KALK_MEK1>
   </ROW>
</ROWSET>
0
 
LVL 35

Expert Comment

by:girionis
ID: 12188262
Do you get any exceptions/errors? If yes then post them please.
0
 

Author Comment

by:vihar123
ID: 12188605
>>>Do you get any exceptions/errors? If yes then post them please.

its quite strange, when im having three nodes for eg:-
1001(angnr)
        |
         10(ver number)
               |
               20( UA number)
on selecting first node, its giving me an exception "java.sql.SQLException: ORA-01722: invalid numberl", one selecting second one its not giving any and on selecting the third one its again giving me the same.

and after selecting one node and clicking action button, its creating and deleting temp.xml but not displaying any values in the db table. its just inserting two blank rows.

when im trying with an other node, its giving the above invalid number exception and also creating temp.xml but its giving me all the below errors and also its not deleting the temp.xml at the close of the file.


oracle.xml.sql.OracleXMLSQLException: 6-byte UTF8 encoding not supported.
        at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:2322)
        at oracle.xml.sql.dml.OracleXMLSave.insertXML(OracleXMLSave.java:1385)
        at gui5.jButton1ActionPerformed(gui5.java:564)
        at gui5.access$200(gui5.java:35)
        at gui5$3.actionPerformed(gui5.java:182)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
        at java.awt.Component.processMouseEvent(Component.java:5100)
        at java.awt.Component.processEvent(Component.java:4897)
        at java.awt.Container.processEvent(Container.java:1569)
        at java.awt.Component.dispatchEventImpl(Component.java:3615)
        at java.awt.Container.dispatchEventImpl(Container.java:1627)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
        at java.awt.Container.dispatchEventImpl(Container.java:1613)
        at java.awt.Window.dispatchEventImpl(Window.java:1606)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)


-------------------
code
------------
 Connection conn1;      
       Statement stmt1;      
       ResultSet rset1 = null;  
     
       
        try
        {
            DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
                     
           
            conn1 =
            DriverManager.getConnection ("");
           
            stmt1 = conn1.createStatement ();
                rset1 = stmt1.executeQuery("select * from regdet");
                
                           while (rset1.next())
               {
                       
                DefaultMutableTreeNode Angnr = new DefaultMutableTreeNode( new TreeSelectionObject(TreeSelectionObject.ANGNR, rset1.getString("ang_nr1")) );
              topnode.add(Angnr);              
              DefaultMutableTreeNode Version = new DefaultMutableTreeNode( new TreeSelectionObject(TreeSelectionObject.VERNR, rset1.getString("ver_nr1")) );
              Angnr.add(Version);
              DefaultMutableTreeNode UA = new DefaultMutableTreeNode( new TreeSelectionObject(TreeSelectionObject.UANR, rset1.getString("faktor1")) );
              Version.add(UA);
           
              }
                              conn1.close();
                              stmt1.close();                                                      
                              rset1.close();
                              
                    jTree1.setRootVisible(true);
                    treeModel.reload();      
                   
                     
        }
                 
        catch (SQLException e)
        {
            System.out.println(e);
        }
       
                         /**** Tree Action *****/
          jTree1.addTreeSelectionListener(new TreeSelectionListener() {
              
                public void valueChanged(TreeSelectionEvent evt) {
                                                                                       
                                 TreePath tp = evt.getNewLeadSelectionPath();
                             Connection conn2;
                               Statement stmt2;
                               ResultSet rset2 = null;
                               DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) tp.getLastPathComponent();                               
                               String empNo = node1.toString();
             
                                                              
                               try
                                {
                              DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
                     
                        conn2 = DriverManager.getConnection ("");
           
                              stmt2 = conn2.createStatement ();
                rset2 = stmt2.executeQuery("select * from regdet WHERE ang_nr1 = '" + empNo + "'");


                                  
                               
                               while (rset2.next())
                           {
                            jTextField1.setText(node1.toString());
                            jTextField2.setText(rset2.getString("ang_nr1"));
                            jTextField3.setText(rset2.getString("prod_bez1"));
                            jTextField4.setText(rset2.getString("kunde_nr1"));
                            jTextField5.setText(rset2.getString("ref_nr1"));
                            jTextField6.setText(rset2.getString("proj_nr1"));
                            jTextField7.setText(rset2.getString("basisprojekt1"));
                            
                           }
                              
                                          conn2.close();
                                          stmt2.close();
                                          rset2.close();
                                     
                                  }                
                 
                 
                          catch (SQLException e)
                                {
                                    System.out.println(e);
                                }
                                                             
                             Connection conn3;
                               Statement stmt3;
                               ResultSet rset3 = null;    
                               DefaultMutableTreeNode node2 = (DefaultMutableTreeNode) tp.getLastPathComponent();                                            
                               String verNo = node2.toString();                               
                               
                   try
                                {
                              DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
                     
                        conn3 = DriverManager.getConnection ("");
           
                              stmt3 = conn3.createStatement ();
                   rset3 = stmt3.executeQuery("select * from regdet WHERE ver_nr1 = '" + verNo + "'");
                                        
                               clearForm();      
                                              
                               while (rset3.next())
                           {
                            jTextField8.setText(rset3.getString("ver_nr1"));
                                    jTextField9.setText(rset3.getString("gesc_jahr1"));
                                    jTextField10.setText(rset3.getString("ver_besh1"));
                                    jTextField11.setText(rset3.getString("curr1"));
                                    jTextField12.setText(rset3.getString("ges_kalk1"));
                                    jTextField13.setText(rset3.getString("kalk_ele1"));
                                    jTextField14.setText(rset3.getString("kalk_mek1"));
                               }
                              
                                          conn3.close();
                                          stmt3.close();
                                          rset3.close();      
                                    
                                  }
                          
                          catch (SQLException e)
                                {
                                    System.out.println(e);
                                }
                                           
                                  //getting the selected node and giving action to it
                                  
                                  
                                  
                                         
                                        }
                              
                                                  
                                                                                                    }
       
                                                          );      
            
    }  
                                  /* Method for clearing the text fields when new project number is selected */
                            private void clearForm()
                                                {
   
                                              jTextField8.setText("");
                                                jTextField9.setText("");
                                                jTextField10.setText("");
                                                jTextField11.setText("");
                                                jTextField12.setText("");
                                                jTextField13.setText("");
                                                jTextField14.setText("");

                                                }
                              
                              
                              
   
    private void jLabel15ComponentMoved(java.awt.event.ComponentEvent evt) {
       
                                                                                                             }
   
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // action code for button
       
        DefaultMutableTreeNode nodeSelected = (DefaultMutableTreeNode)jTree1.getSelectionPath().getLastPathComponent();
                      TreeSelectionObject obj = (TreeSelectionObject) nodeSelected.getUserObject();
                                        String angNumber = null;
                                  
                                           
                               if ( obj.getType() == TreeSelectionObject.ANGNR ) {    
                                       angNumber = obj.getNumber();
                                       System.out.println(obj);
                                                                                                            
                                                                                                 }
                        else if ( obj.getType() == TreeSelectionObject.VERNR ) {  
                                                                              System.out.println(obj);
                     DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)nodeSelected.getParent();
                                          obj = (TreeSelectionObject)parentNode.getUserObject();
                                          angNumber = obj.getNumber();
                                          System.out.println("parent"+obj);
                                           
else if ( obj.getType() == TreeSelectionObject.UANR ) {
                                               System.out.println(obj);
            DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)nodeSelected.getParent().getParent();
                                           obj = (TreeSelectionObject)parentNode.getUserObject();
                                    angNumber = obj.getNumber();  
                                     System.out.println("parent"+obj);
                                          
                                      
                               
                            //xml code//
                             Connection conn;
                                try
                                {
                              DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());                      
                        conn = DriverManager.getConnection ("");
         OracleXMLQuery qry = new OracleXMLQuery(conn, "select * from regdet WHERE ang_nr1 = '" + angNumber + "'");
                              
                              String sx = qry.getXMLString();
                              String tableName = "xins";
                            
                              String fileName =  "I:/Gotla/java/temp.xml";
                                
                                    try {
                                           OracleXMLSave save = new OracleXMLSave(conn, tableName);
                                            //File theFile = File.createTempFile("myApp", "xml");
                                            //theFile.deleteOnExit();
                                                
                                                
                                                File theFile = new File(fileName);
                                                if (theFile.exists())                                                                               theFile.delete();
                                                if (theFile.createNewFile() )              
                                                   theFile.deleteOnExit();
                  System.out.println("file created successfully");
                                 try {
                                BufferedWriter out = new BufferedWriter(new FileWriter(theFile));                                                              out.write(sx);                                                        
                                                        out.flush();
                                                        out.close();
                                                                  } catch (IOException e) {
                                                                        }

                         InputStream is = new FileInputStream(fileName);
                                          int rowCount = save.insertXML(is);              
                                          is.close();
                                          
System.out.println("Inserted successfully" + "  " + "*"+ rowCount +"*"+ "  " + "rows into" + "  " + tableName);      
                               
                                    }
                                      catch (IOException e) {
                                             System.out.println(e);
                                                         
                                                           }
                              
                                   
                                }
                          catch (SQLException e)
                                {
                                    e.printStackTrace();      
                                      System.out.println(e);
                                }
                                                                                                              
                                                                                                                     }
       
                                                                                                             }
0
 
LVL 35

Expert Comment

by:girionis
ID: 12188642
For the oracle error message have a look here: http://www.orafaq.com/error/ora-01722.htm

For the OracleXMLSQLException it seems that you are saving the content in an encoding that is not understood. Try changing the encoding of the xml file.
0
 

Author Comment

by:vihar123
ID: 12188704
>>>>For the OracleXMLSQLException it seems that you are saving the content in an encoding that is not understood. Try changing the encoding of the xml file.

can u please tell me how to do it, actually i dont want to change anything manually in the xml file, i want to use it only to carry my data, so i dont understand why for each node its acting differently????
0
 
LVL 35

Expert Comment

by:girionis
ID: 12188852
> so i dont understand why for each node its acting differently????

Maybe each node has different encoding (non-ascii characters)?
0
 

Author Comment

by:vihar123
ID: 12188923
leaving the display of data, why is it deletíng the 2 xml file and why is it not deleting the 1 xml, and why is it giving all these errors when im trying to send 1 xml

not solving but i want to understand why??


1 xml
-------
<?xml version = '1.0'?>
<ROWSET>
   <ROW num="1">
      <ANG_NR1>1425.001</ANG_NR1>
      <PROD_BEZ1>NüW Montagelinie manuell D26</PROD_BEZ1>
      <KUNDE_NR1>16</KUNDE_NR1>
      <FAKTOR1>1.08</FAKTOR1>
      <VER_NR1>1</VER_NR1>
      <VER_BESH1>Angebotskalk.</VER_BESH1>
      <GESC_JAHR1>2004</GESC_JAHR1>
      <CURR1>EUR</CURR1>
      <GES_KALK1>Rummel</GES_KALK1>
      <KALK_MEK1>Hirsch</KALK_MEK1>
      <KALK_ELE1>Rummel</KALK_ELE1>
   </ROW>
   <ROW num="2">
      <ANG_NR1>1425.001</ANG_NR1>
      <PROD_BEZ1>NüW Montagelinie manuell D26</PROD_BEZ1>
      <KUNDE_NR1>16</KUNDE_NR1>
      <FAKTOR1>1.08</FAKTOR1>
      <VER_NR1>2</VER_NR1>
      <VER_BESH1>ungültig</VER_BESH1>
      <GESC_JAHR1>2004</GESC_JAHR1>
      <CURR1>EUR</CURR1>
      <GES_KALK1>Rummel</GES_KALK1>
      <KALK_MEK1>Hirsch</KALK_MEK1>
      <KALK_ELE1>Rummel</KALK_ELE1>
      <REF_NR1>1425.001    </REF_NR1>
   </ROW>
</ROWSET>


----

2 xml
------

<?xml version = '1.0'?>
<ROWSET>
   <ROW num="1">
      <ANG_NR1>0015.000</ANG_NR1>
      <PROD_BEZ1>Test-Eraslan Test-DB-Praktikanten</PROD_BEZ1>
      <KUNDE_NR1>24</KUNDE_NR1>
      <FAKTOR1>1.08</FAKTOR1>
      <BASISPROJEKT1>1234</BASISPROJEKT1>
      <VER_NR1>1</VER_NR1>
      <VER_BESH1>test eraslan test-db Praktikanten</VER_BESH1>
      <GESC_JAHR1>2004</GESC_JAHR1>
      <CURR1>EUR</CURR1>
      <GES_KALK1>Schlegel</GES_KALK1>
      <KALK_MEK1>Schlegel</KALK_MEK1>
      <KALK_ELE1>Schlegel</KALK_ELE1>
      <REF_NR1>1219.001</REF_NR1>
   </ROW>
   <ROW num="2">
      <ANG_NR1>0015.000</ANG_NR1>
      <PROD_BEZ1>Test-Eraslan Test-DB-Praktikanten</PROD_BEZ1>
      <KUNDE_NR1>24</KUNDE_NR1>
      <FAKTOR1>1.08</FAKTOR1>
      <BASISPROJEKT1>1234</BASISPROJEKT1>
      <VER_NR1>2</VER_NR1>
      <VER_BESH1>Test Arun</VER_BESH1>
      <GESC_JAHR1>2004</GESC_JAHR1>
      <CURR1>EUR</CURR1>
      <KALK_MEK1>Arun</KALK_MEK1>
   </ROW>
</ROWSET>
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12188993
>> its giving me all the below errors and also its not deleting the temp.xml at the close of the file.
When it gives you errors don't expect the temp file to be deleted.
It's only deleted on a "normal" program exit, not when an exception is thrown.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12189171
>oracle.xml.sql.OracleXMLSQLException: 6-byte UTF8 encoding not supported

So like suggest before specify an encoding (supported by OracleXML)
I believe you use a non correct charset.
https://cwisdb.cc.kuleuven.ac.be/ora10doc/server.101/b10749/glossary.htm
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12189184
encoding="iso-8859-1" for example goes well?
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12189194
I see this:
XML-20063: 6-byte UTF8 encoding not supported
Cause: The XML Parser does not support 6-byte UTF8 encoding scheme. It is also possible that invalid UTF8 characters were misinterpreted as 6-byte UTF8 encoding.
Action: If the data contains invalid UTF8 bytes, fix the input, otherwise if 6-byte UTF8 supported is required, please contact Oracle Support.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12225085
Sorry for not help you.
Bye, Giant.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12225098
Thanks
I wish we could have helped you better than this.
Did you solved it at last?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12229518
8-)
0
 

Author Comment

by:vihar123
ID: 12250046
>>>Did you solved it at last?

not really, but im doing some other imp stuff now.....so will get back with this later, anyway thanks for everything. :-)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now