Revision 436
Added by berkley over 24 years ago
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
222 | 222 |
} |
223 | 223 |
|
224 | 224 |
/** |
225 |
* returns a string array of the contents of a particular node. |
|
226 |
* If the node appears more than once, the contents are returned |
|
227 |
* in the order in which they appearred in the document. |
|
228 |
* @param nodename the name or path of the particular node. |
|
229 |
* @param docid the docid of the document you want the node from. |
|
230 |
* @param conn a database connection-this allows this method to be static |
|
231 |
*/ |
|
232 |
public static Object[] getNodeContent(String nodename, String docid, |
|
233 |
Connection conn) |
|
234 |
{ |
|
235 |
StringBuffer query = new StringBuffer(); |
|
236 |
Vector result = new Vector(); |
|
237 |
PreparedStatement pstmt; |
|
238 |
query.append("select nodedata from xml_nodes where parentnodeid in "); |
|
239 |
query.append("(select nodeid from xml_index where path like '"); |
|
240 |
query.append(nodename); |
|
241 |
query.append("' and docid like '").append(docid).append("')"); |
|
242 |
try |
|
243 |
{ |
|
244 |
pstmt = conn.prepareStatement(query.toString()); |
|
245 |
|
|
246 |
// Execute the SQL query using the JDBC connection |
|
247 |
pstmt.execute(); |
|
248 |
ResultSet rs = pstmt.getResultSet(); |
|
249 |
boolean tableHasRows = rs.next(); |
|
250 |
while (tableHasRows) |
|
251 |
{ |
|
252 |
result.add(rs.getString(1)); |
|
253 |
System.out.println(rs.getString(1)); |
|
254 |
tableHasRows = rs.next(); |
|
255 |
} |
|
256 |
} |
|
257 |
catch (SQLException e) |
|
258 |
{ |
|
259 |
System.err.println("Error getting id: " + e.getMessage()); |
|
260 |
} |
|
261 |
|
|
262 |
return result.toArray(); |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
225 | 266 |
* format a structured query as an XML document that conforms |
226 | 267 |
* to the pathquery.dtd and is appropriate for submission to the DBQuery |
227 | 268 |
* structured query engine |
... | ... | |
441 | 482 |
|
442 | 483 |
/** |
443 | 484 |
* '$Log$ |
485 |
* 'Revision 1.17 2000/08/31 21:20:39 berkley |
|
486 |
* 'changed xslf for new returnfield scheme. the returnfields are now returned as <param name="<returnfield>"> tags. |
|
487 |
* 'hThe sql for the returnfield query was redone to fix a previous problem with slow queries |
|
488 |
* ' |
|
444 | 489 |
* 'Revision 1.16 2000/08/23 22:55:25 berkley |
445 | 490 |
* 'changed the field names to be case-sensitive in the returnfields |
446 | 491 |
* ' |
Also available in: Unified diff
Added a method called getNodeContent which retrieves the content of a node in a document. If there are more than one nodes with the same name returned, it returns an array with all of the data.