/* * @(#)FindSpecialString.java 2009-8-10 * Copyright 2008 UFIDA Software CO.LTD. All rights reserved. */ package com.hongqishi.exportdata; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.Enumeration; import java.util.HashMap; import java.util.Properties; /** * TODO 简要说明 * <p> * * @function 导出最新的流程定义 * @author Administrator * @version 1.0 2009-8-10 * @since NC5.5 */ public class ExportIc_special_h { /** * @author: zhangrenyang * @function: * @parameter: none * @return: none * @exception: none * @throws * @date: 2009-8-10上午10:43:13 * @since: V5.5 * @commet modified date modifier */ public static void main(String[] args) throws SQLException { HashMap map = new HashMap(); try { Properties p = new Properties(); p.load(new FileInputStream("E://NC LESSON//dictpropcn.properties")); for (Enumeration e = p.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); map.put(key, p.getProperty(key)); } } catch (Exception e) { System.out.println(e); } try { File file = new File("D://datacompare//ic_special_h.htm"); File file2 = new File("D://datacompare//ic_special_h_new.htm"); BufferedReader reader = new BufferedReader(new FileReader(file)); PrintWriter writer = new PrintWriter(file2); String line; while ((line = reader.readLine()) != null) { // 判断条件,根据自己的情况书写,会删除所有符合条件的行 if (line.indexOf("</table>") != -1 || line.indexOf("</body>") != -1 || line.indexOf("</html>") != -1) { continue;// 如果是不读后面的话就停止读取了 } writer.println(line); writer.flush(); } reader.close(); writer.close(); // 删除老文件 file.delete(); file2.renameTo(file); } catch (Exception ex) { ex.printStackTrace(); } String fileName = "D://datacompare//ic_special_h.htm"; FileWriter fw = null; PrintWriter toFile = null; try { fw = new FileWriter(fileName, true); toFile = new PrintWriter(fw); } catch (FileNotFoundException e) { System.out.println("PrintWriter error opening the file " + fileName); System.exit(0); } catch (IOException e) { System.out.println("FileWriter error opening the file " + fileName); System.exit(0); } Connection conn = null; Statement stmt = null; ResultSet rs = null; StringBuffer sb = new StringBuffer(); try { // InputStreamReader is_reader = new InputStreamReader(System.in); // String str = new BufferedReader(is_reader).readLine(); String str = "1"; Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.10.221:1521:ufida", "ncv55", "ncv55"); stmt = conn.createStatement(); rs = stmt.executeQuery("select * from ic_special_h order by ts desc"); ResultSetMetaData meta = rs.getMetaData(); Object name; if ("1".equals(str) || "3".equals(str)) { sb.append("<thead>"); for (int i = 1; i <= meta.getColumnCount(); i++) { sb.append("<th>" + meta.getColumnName(i).toLowerCase() + "(" + map.get("ic_special_h$" + meta.getColumnName(i).toLowerCase()) + ")</th>"); } sb.append("</thead>"); } if ("2".equals(str) || "3".equals(str)) { sb.append("<tr>"); if (rs.next()) { for (int i = 1; i < meta.getColumnCount(); i++) { name = rs.getObject(i) == null ? "" : rs.getObject(i); sb.append("<td>" + name.toString() + "</td>"); } } sb.append("</tr>"); } sb.append("/n</table></body></html>"); } catch (Exception ex) { System.out.println("出现的异常为" + ex); } rs.close(); stmt.close(); conn.close(); toFile.println(sb); toFile.close(); System.out.println(sb.toString()); } }