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

public static void main(String[] args) throws 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);
            };
        }

往数据库中插入了10000条数据

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