Project

General

Profile

« Previous | Next » 

Revision 12

Added by Matt Jones over 25 years ago

added Text insertion to database

View differences:

DBElement.java
98 98
        }
99 99

  
100 100
	if (hasChildNodes())
101
	    writeChildrenXmlToDB(conn, newid);
101
            try {
102
	      writeChildrenXmlToDB(conn, newid);
103
            } catch (SQLException e) {
104
              System.out.println(e.getMessage());
105
            }
102 106

  
103 107
        System.out.println("ID: " + newid + "\tTag: " + getTagName());
104 108
    }
105 109

  
106 110
    public void writeChildrenXmlToDB(Connection conn, int parentID) 
107
		throws IOException {
111
		throws IOException, SQLException {
108 112

  
109 113
      NodeList children = getChildNodes();
110 114
      if (children != null) {
111 115
        for (int i = 0; i < children.getLength(); i++) {
112 116
          if (children.item(i) instanceof ElementNode) {
113 117
            ((DBElement)children.item(i)).writeXmlToDB(conn, parentID);
118
          } else if (children.item(i) instanceof Text) {
119
             // Write the text to the now created parent node
120
             PreparedStatement pstmt = conn.prepareStatement(
121
                "UPDATE xml_elements SET nodedata = ? " + 
122
		"WHERE nodeid = ?");
123
             pstmt.setString(1, ((Text)children.item(i)).getNodeValue()); 
124
             pstmt.setInt(2, parentID); 
125
             pstmt.execute();
126
             pstmt.close();
114 127
          } else {
115
            System.out.println("    Text Node skipped.");
128
            System.out.println("    Other Node Type skipped.");
116 129
          }
117 130
        }
118 131
      }

Also available in: Unified diff