Revision 50
Added by Matt Jones about 24 years ago
DBReader.java | ||
---|---|---|
57 | 57 |
dbstring = args[3]; |
58 | 58 |
} |
59 | 59 |
|
60 |
DBReader rd = new DBReader(user, password, dbstring); |
|
60 |
// Open a connection to the database |
|
61 |
Connection dbconn = MetaCatUtil.openDBConnection( |
|
62 |
"oracle.jdbc.driver.OracleDriver", |
|
63 |
dbstring, user, password); |
|
64 |
|
|
65 |
DBReader rd = new DBReader( dbconn ); |
|
61 | 66 |
String xml = rd.readXMLDocument(nodeid); |
62 | 67 |
System.out.println(xml); |
63 | 68 |
|
... | ... | |
74 | 79 |
* |
75 | 80 |
* Generally, one calls readXMLDocument() after constructing the instance |
76 | 81 |
* |
77 |
* @param user the username to use for the database connection |
|
78 |
* @param password the password to use for the database connection |
|
79 |
* @param dbstring the connection info to use for the database connection |
|
82 |
* @param conn the database connection from which to read the document |
|
80 | 83 |
*/ |
81 |
public DBReader( String user, String password, String dbstring)
|
|
84 |
public DBReader( Connection conn )
|
|
82 | 85 |
throws IOException, |
83 | 86 |
SQLException, |
84 | 87 |
ClassNotFoundException |
85 | 88 |
{ |
86 |
// Open a connection to the database |
|
87 |
conn = openDBConnection( |
|
88 |
"oracle.jdbc.driver.OracleDriver", |
|
89 |
dbstring, user, password); |
|
90 |
|
|
89 |
this.conn = conn; |
|
91 | 90 |
} |
92 | 91 |
|
93 |
/** open a connection to the database with the supplied information */ |
|
94 |
private Connection openDBConnection(String dbDriver, String connection, |
|
95 |
String user, String password) |
|
96 |
throws SQLException, ClassNotFoundException { |
|
97 |
// Load the Oracle JDBC driver |
|
98 |
Class.forName (dbDriver); |
|
99 |
|
|
100 |
// Connect to the database |
|
101 |
Connection conn = DriverManager.getConnection( connection, user, password); |
|
102 |
return conn; |
|
103 |
} |
|
104 |
|
|
105 | 92 |
/** |
106 | 93 |
* Create an XML document from the database starting with the element |
107 | 94 |
* having element_id nodeid |
Also available in: Unified diff
changed database connection code, added utility class MetaCatUtil.java