1 16 17 import java.util.Map ; 18 import java.util.Iterator ; 19 20 23 public class RowInserterRule extends org.apache.commons.digester.Rule { 24 25 private java.sql.Connection conn; 26 27 public RowInserterRule(java.sql.Connection conn) { 28 this.conn = conn; 29 } 30 31 37 public void begin(String namespace, String name, org.xml.sax.Attributes attrs) { 38 digester.push(new Row()); 39 } 40 41 55 public void end(String namespace, String name) { 56 Row row = (Row) digester.pop(); 57 Table table = (Table) digester.peek(); 58 59 67 StringBuffer colnames = new StringBuffer (); 68 StringBuffer colvalues = new StringBuffer (); 69 70 for(Iterator i = row.getColumns().iterator(); i.hasNext();) 71 { 72 Row.Column column = (Row.Column) i.next(); 73 74 if (colnames.length() > 0) 75 { 76 colnames.append(", "); 77 colvalues.append(", "); 78 } 79 80 colnames.append("'"); 81 colnames.append(column.getName()); 82 colnames.append("'"); 83 84 colvalues.append("'"); 85 colvalues.append(column.getValue()); 86 colvalues.append("'"); 87 } 88 89 StringBuffer buf = new StringBuffer (); 90 buf.append("insert into "); 91 buf.append(table.getName()); 92 buf.append(" ("); 93 buf.append(colnames.toString()); 94 buf.append(") values ("); 95 buf.append(colvalues.toString()); 96 buf.append(")"); 97 98 System.out.println(buf.toString()); 100 } 101 } 102 | Popular Tags |