Revision 23
Added by Matt Jones over 24 years ago
ReaderElement.java | ||
---|---|---|
13 | 13 |
|
14 | 14 |
import java.sql.*; |
15 | 15 |
import java.io.IOException; |
16 |
import java.util.Hashtable;
|
|
16 |
import java.util.Vector;
|
|
17 | 17 |
import java.util.Enumeration; |
18 | 18 |
|
19 | 19 |
public class ReaderElement extends BasicElement { |
20 | 20 |
|
21 |
private Connection conn; |
|
21 |
private Connection conn; |
|
22 |
private Vector children; |
|
22 | 23 |
|
23 | 24 |
public ReaderElement (Connection conn, long nodeid) { |
24 | 25 |
|
25 | 26 |
this.conn = conn; |
27 |
|
|
26 | 28 |
//Lookup data for self |
27 |
String tagname = "foo"; |
|
28 |
long parent_id = 999; |
|
29 |
super(tagname, parent_id); |
|
29 |
getElementInfo(nodeid); |
|
30 | 30 |
|
31 | 31 |
//Lookup list of child nodes |
32 | 32 |
//foreach childnode (childid,childtype) |
... | ... | |
39 | 39 |
//} |
40 | 40 |
|
41 | 41 |
} |
42 |
|
|
43 |
private void getElementInfo(long nodeid) { |
|
44 |
long element_id=0; |
|
45 |
long parentnodeid=0; |
|
46 |
String nodetype=null; |
|
47 |
String nodename=null; |
|
48 |
String nodedata=null; |
|
49 |
|
|
50 |
PreparedStatement pstmt; |
|
51 |
try { |
|
52 |
pstmt = |
|
53 |
conn.prepareStatement("SELECT nodeid,parentnodeid,nodetype, " + |
|
54 |
"nodename,nodedata FROM xml_nodes WHERE nodeid = ?"); |
|
55 |
// Bind the values to the query |
|
56 |
pstmt.setLong(1, nodeid); |
|
57 |
|
|
58 |
pstmt.execute(); |
|
59 |
try { |
|
60 |
ResultSet rs = pstmt.getResultSet(); |
|
61 |
try { |
|
62 |
boolean tableHasRows = rs.next(); |
|
63 |
if (tableHasRows) { |
|
64 |
try { |
|
65 |
element_id = rs.getLong(1); |
|
66 |
parentnodeid = rs.getLong(2); |
|
67 |
nodetype = rs.getString(3); |
|
68 |
nodename = rs.getString(4); |
|
69 |
nodedata = rs.getString(5); |
|
70 |
} catch (SQLException e) { |
|
71 |
System.out.println("Error with getInt: " + e.getMessage()); |
|
72 |
} |
|
73 |
} |
|
74 |
} catch (SQLException e) { |
|
75 |
System.out.println("Error with next: " + e.getMessage()); |
|
76 |
} |
|
77 |
} catch (SQLException e) { |
|
78 |
System.out.println("Error with getrset: " + e.getMessage()); |
|
79 |
} |
|
80 |
pstmt.close(); |
|
81 |
} catch (SQLException e) { |
|
82 |
System.out.println("Error getting id: " + e.getMessage()); |
|
83 |
} |
|
84 |
|
|
85 |
if (nodetype.equals("ELEMENT")) { |
|
86 |
setElementID(element_id); |
|
87 |
setParentID(parentnodeid); |
|
88 |
setTagName(nodename); |
|
89 |
content.append(nodedata); |
|
90 |
} |
|
91 |
} |
|
42 | 92 |
} |
Also available in: Unified diff
adding recursive build for ReaderElement