Revision 50
Added by Matt Jones about 24 years ago
DBSAXWriter.java | ||
---|---|---|
66 | 66 |
dbstring = args[3]; |
67 | 67 |
} |
68 | 68 |
|
69 |
new DBSAXWriter(filename, user, password, dbstring); |
|
69 |
// Open a connection to the database |
|
70 |
Connection dbconn = MetaCatUtil.openDBConnection( |
|
71 |
"oracle.jdbc.driver.OracleDriver", |
|
72 |
dbstring, user, password); |
|
73 |
|
|
74 |
new DBSAXWriter(filename, dbconn); |
|
70 | 75 |
System.out.println("Document processing finished for: " + filename); |
71 | 76 |
|
72 | 77 |
} catch (Exception e) { |
... | ... | |
81 | 86 |
* construct a new instance of the class to write an XML file to the database |
82 | 87 |
* |
83 | 88 |
* @param filename the filename to be loaded into the database |
84 |
* @param user the username to use for the database connection |
|
85 |
* @param password the password to use for the database connection |
|
86 |
* @param dbstring the connection info to use for the database connection |
|
89 |
* @param conn the database connection to which to write the XML file |
|
87 | 90 |
*/ |
88 |
public DBSAXWriter( String filename, String user, |
|
89 |
String password, String dbstring) |
|
91 |
public DBSAXWriter( String filename, Connection conn) |
|
90 | 92 |
throws IOException, |
91 | 93 |
SQLException, |
92 | 94 |
ClassNotFoundException |
93 | 95 |
{ |
94 |
// Open a connection to the database |
|
95 |
conn = openDBConnection( |
|
96 |
"oracle.jdbc.driver.OracleDriver", |
|
97 |
dbstring, user, password); |
|
98 |
|
|
96 |
this.conn = conn; |
|
99 | 97 |
|
100 | 98 |
// |
101 | 99 |
// Set up the SAX document handlers for parsing |
... | ... | |
143 | 141 |
|
144 | 142 |
} |
145 | 143 |
|
146 |
/** Utility method to establish the JDBC connection */ |
|
147 |
private Connection openDBConnection(String dbDriver, String connection, |
|
148 |
String user, String password) |
|
149 |
throws SQLException, ClassNotFoundException { |
|
150 |
// Load the Oracle JDBC driver |
|
151 |
Class.forName (dbDriver); |
|
152 |
|
|
153 |
// Connect to the database |
|
154 |
Connection conn = DriverManager.getConnection( connection, user, password); |
|
155 |
return conn; |
|
156 |
} |
|
157 |
|
|
158 | 144 |
/** Utility method to convert a file handle into a URL */ |
159 | 145 |
static public URL fileToURL(File file) |
160 | 146 |
{ |
Also available in: Unified diff
changed database connection code, added utility class MetaCatUtil.java