/*
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);
}
}
}
|