今天因为要输出形如下面的语句:
recordVO.addElement("REPORT_ID", rs.getString("REPORT_ID"));
尝试写个小程序来实现该种形式的输出:
        private String temp = "recordVO.addElement(\"%rowname%\", rs.%getmethod%(\"%rowname%\"));\n";

         public void doAddElmtGene() throws Exception {
                StringBuffer sbValue = new StringBuffer(512);
                Connection conn = OracleTmplTblTest.getConnection();
                DatabaseMetaData dbmd = conn.getMetaData();
                ResultSet rs = dbmd.getColumns( null, dbmd.getUserName(), "CS_SS_ACCIDENT_DEVICE_REPORT", null);
                 while (rs.next()) {
                        sbValue.append( this.getOutputStr(rs.getString( "COLUMN_NAME"), rs.getInt( "DATA_TYPE")));
                }
                System.out.println(sbValue);
        }

         private String getOutputStr(String rowname, int type) {
                Map values = new HashMap();
                values.put( "rowname", rowname);
                String getmethod = "";
                 if (type == Types.DECIMAL || type == Types.VARCHAR) {
                        getmethod = "getString";
                } else if (type == Types.DATE || type == Types.TIME | type == Types.TIMESTAMP) {
                        getmethod = "getDate";
                } else if (type == Types.BLOB) {
                        getmethod = "getBlob";
                }
                values.put( "getmethod", getmethod);
                 return this.getRenderStr(values);
        }

         private String getRenderStr(Map values) {
                String value = temp;
                Iterator it = values.keySet().iterator();
                String key = null;
                 while (it.hasNext()) {
                        key = (String) it.next();
                        value = value.replaceAll( "%" + key + "%", (String) values.get(key));
                }
                 return value;
        }

         public static void main(String[] args) {
                GeneRe g = new GeneRe();
                 try {
                        g.doAddElmtGene();
                } catch (Exception e) {
                         // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }