1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Date;
import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException;
/** * quartz定时器测试 * * @author leizhimin 2009-7-23 8:49:01 */
public class MyJob implements Job { public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { System.out.println("begin:" + new Date() ); Connection con = null;// 创建一个数据库连接 PreparedStatement pre = null;// 创建预编译语句对象,一般都是用这个而不用Statement ResultSet result = null;// 创建一个结果集对象 int intDML = 0; String orgWords = "haha"; String newWords = "***"; String tmpStr = ""; try { Class.forName("oracle.jdbc.driver.OracleDriver"); String url="jdbc:oracle:thin:@xxxxxxxx:1526:xxx"; //orcl为数据库的SID String userName = "xxx"; String passWord = "xxx"; String sql = "SELECT * FROM nbu_notice_info i where i.notice_state =?"; con= DriverManager.getConnection(url,userName,passWord); System.out.println("connect sucessfully..."); pre = con.prepareStatement(sql); pre.setString(1, "Y"); result = pre.executeQuery(); System.out.println("query sucessfully..."); String content = ""; String primaryKey = ""; int index = -1 ; while (result.next()) { primaryKey = result.getString(1); content = result.getString(3); System.out.println("content = " + content ); if ((index = content.indexOf(orgWords)) != -1){ System.out.println("存在敏感信息" + orgWords); tmpStr = content.substring(0,index) + newWords + content.substring(index + orgWords.length(),content.length()); System.out.println("modify sucessfully... \n\ttmpStr = " + tmpStr); sql = "UPDATE nbu_notice_info I SET i.notice_content = ? WHERE i.id_notice_sequence= ?"; pre = con.prepareStatement(sql); pre.setString(1, tmpStr); pre.setString(2, primaryKey); intDML = pre.executeUpdate(); System.out.println("DML执行结果:" + intDML + "行数据已修改!"); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { con.close(); System.out.println("end:" + new Date() ); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static void main(String[] args) {
} }
|