往数据库中插入不定数量的数据

 public static void main(String[] args) {   
           Integer cacheTime = 1000 * 10;   
           Timer timer = new Timer();   
           // (TimerTask task, long delay, long period)任务,延迟时间,多久执行   
            timer.schedule(new TimerTask() {   
               @Override  
              public void run() {   
                   try {
                    Update();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
               }   
          }, 10000, cacheTime);   
        }  

public  static  void Update() throws SQLException, ClassNotFoundException  {
        
    try{
        String dbUrl = "jdbc:oracle:thin:@localhost:1521:ORCL"; 
        String user = "scott"; 
        String password = "tiger"; 
        Class.forName("oracle.jdbc.driver.OracleDriver"); //加载JDBC驱动
        Connection c = DriverManager.getConnection(dbUrl, user, password); //建立连接
        System.out.println("连接成功");
        Statement s = c.createStatement();//采用Statement进行插入数据
        //long i=0;
        String nb="10000";
        String NBR="11111100000";//11位
        String sql="";
        for(int i=0;i<10000;i++){
         sql="insert into wangkun"+
        "(ORDER_SERIAL_NBR, PRD_CODE, SERV_ID, ACC_NBR, ACTION, ORDER_STATE, SOURCE, CREATE_DATE, STATE, STATE_DATE, LATN_ID, BUREAU_ID, IF_QUOTA, PRIORITY, STAFF_ID, STAFF_NAME, COMMENTS, AREA_ID, MDSE_PROD_CODE, PROD_TYPE, MDSE_PROD_VALUE, EFFECTIVE_DATE, REMARK, CUST_LEVEL)"+
        "values ("+nb+", '42010100', 100395403, '"+NBR+"', 6, '5SA', '10', to_date('30-09-2012 06:24:41', 'dd-mm-yyyy hh24:mi:ss'), '5SN', to_date('28-09-2012 13:33:36', 'dd-mm-yyyy hh24:mi:ss'), 551, null, null, 65, null, null, null, null, '11010100', 1, null, '20110624062438', '人工停复机', 10)";
        s.executeUpdate(sql); //插入数据
        System.out.println("插入数据成功,插入的行数为"+i);
        c.commit();
        nb=String.valueOf(Long.valueOf(nb)+1);
        NBR=String.valueOf(Long.valueOf(NBR)+1);
        }
        System.out.println(sql);
        //String sql="update tb_int_tfj_551 set STATE='5SN'";
        //s.executeUpdate(sql);
        s.close();
        c.close(); //关闭数据库连接
        System.out.println("数据库连接已关闭");
        
        }catch(SQLException e){
            System.out.println(e);
        }

 

posted @ 2012-09-28 16:27  合肥房屋托管  阅读(404)  评论(0编辑  收藏  举报