XML Databases DOM : XML Database : XML : Java examples (example source code) Organized by topic

Java
C++
PHP
Java Home »  XML   » [  XML Database  ]  Screenshots 
 



XML Databases DOM


/*
  Java, XML, and Web Services Bible
  Mike Jasnowski
  ISBN: 0-7645-4847-6
*/
import java.sql.*;
import java.io.*;
import org.apache.xerces.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
 
public class XMLDBDOM {     
  
     public static void main (String[] args) {
 
          try {
               Class.forName("COM.cloudscape.core.JDBCDriver").newInstance();
           
               Connection conn = DriverManager.getConnection(
                "jdbc:cloudscape:GAMETRADER");
                 
               // Set AutoCommit to false //
               conn.setAutoCommit(false);
                 
               // Create a table to hold the manuals for the games //
               Statement s = conn.createStatement();
               s.executeUpdate("CREATE TABLE MANUALS(GAMEID INT, MANUAL SERIALIZE(org.w3c.dom.Document))");
               conn.commit();
                
               // Open an read XML document representing game manual //
               File file = new File("manuals.xml");
               InputStream is = new FileInputStream(file);
                
               // Create a preparedstatement to execute the update //
               PreparedStatement ps =  
                    conn.prepareStatement("INSERT INTO MANUALS VALUES(?,?)");
                
               // Set the value of the first parameter GAMEID //
               ps.setInt(1,1285757);
                
               // Set the value of the second parameter MANUAL //
               // Read in an parse the document                //
               DOMParser parser = new DOMParser();
               parser.parse("manuals.xml");
               Document manual = parser.getDocument();
               ps.setObject(2,manual);
                
               // Execute the update //
               ps.execute();
                
               conn.commit();               
                
 
          }    catch (Throwable e) {
               System.out.println("exception thrown");
               System.out.println(e);
          }
     }
}


           
       
Related examples in the same category
1.  XML Databases and Tools 3
2.   XML Databases and Tools 1
3.  XML Databases and Tools 2








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.