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