1
|
/**
|
2
|
* Name: DBSAXDocument.java
|
3
|
* Purpose: A Class that writes an XML document main data
|
4
|
* Copyright: 2000 Regents of the University of California and the
|
5
|
* National Center for Ecological Analysis and Synthesis
|
6
|
* Authors: Jivka Bojilova
|
7
|
*
|
8
|
* Version: '$Id: DBSAXDocument.java 122 2000-06-07 00:43:31Z jones $'
|
9
|
*/
|
10
|
|
11
|
package edu.ucsb.nceas.metacat;
|
12
|
|
13
|
import java.sql.*;
|
14
|
import java.io.IOException;
|
15
|
import java.util.Hashtable;
|
16
|
import java.util.Enumeration;
|
17
|
|
18
|
/**
|
19
|
* A Class that writes an XML document main data to a database connection
|
20
|
*/
|
21
|
public class DBSAXDocument {
|
22
|
|
23
|
private Connection conn;
|
24
|
private long rootnodeid;
|
25
|
private String docname;
|
26
|
private String doctype;
|
27
|
|
28
|
/**
|
29
|
* Construct a new document instance
|
30
|
*
|
31
|
* @param conn the JDBC Connection to which all information is written
|
32
|
* @param rootnodeid - sequence id of the root node in the document
|
33
|
* @param docname - the name of DTD, i.e. the name immediately following
|
34
|
* the DOCTYPE keyword - should be the root element name.
|
35
|
* (Oracle's and IBM parsers are not aware if it is not the
|
36
|
* root element name)
|
37
|
* @param doctype - Public ID of the DTD, i.e. the name immediately
|
38
|
* following the PUBLIC keyword in DOCTYPE declaration.
|
39
|
*
|
40
|
*/
|
41
|
public DBSAXDocument (Connection conn, long rootnodeid, String docname,
|
42
|
String doctype)
|
43
|
{
|
44
|
this.conn = conn;
|
45
|
this.rootnodeid = rootnodeid;
|
46
|
this.docname = docname;
|
47
|
this.doctype = doctype;
|
48
|
writeDocumentToDB();
|
49
|
}
|
50
|
|
51
|
/** creates SQL code and inserts new document into DB connection */
|
52
|
private void writeDocumentToDB() {
|
53
|
try {
|
54
|
conn.setAutoCommit(false);
|
55
|
PreparedStatement pstmt;
|
56
|
pstmt = conn.prepareStatement(
|
57
|
"INSERT INTO xml_documents " +
|
58
|
"(docid, rootnodeid, docname, doctype) " +
|
59
|
"VALUES (null, ?, ?, ?)");
|
60
|
|
61
|
// Bind the values to the query
|
62
|
pstmt.setLong(1, rootnodeid);
|
63
|
pstmt.setString(2, docname);
|
64
|
pstmt.setString(3, doctype);
|
65
|
// Do the insertion
|
66
|
pstmt.execute();
|
67
|
pstmt.close();
|
68
|
conn.commit();
|
69
|
conn.setAutoCommit(true);
|
70
|
} catch (SQLException e) {
|
71
|
System.out.println(e.getMessage());
|
72
|
}
|
73
|
}
|
74
|
|
75
|
}
|