XML Databases and Tools 2 : XML Database : XML : Java examples (example source code) Organized by topic

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



XML Databases and Tools 2


/*
  Java, XML, and Web Services Bible
  Mike Jasnowski
  ISBN: 0-7645-4847-6
*/
import java.sql.*;
import java.io.*;
 
public class XMLBlob {     
  
     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 LONG VARCHAR)");
               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 //
               ps.setAsciiStream(2,is,(int)file.length());
                
               // 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 DOM








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