批量向数据库增添数据

版权声明:转载请指明出处 https://blog.csdn.net/weixin_42321963/article/details/82389336
package com.xing;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        MyDb db = new MyDb();
        Random r = new Random();
        String name = "";
        System.out.println(name);
        String score = "";
        for (int i = 0; i < 1000; i++) {
            name = Str(3 + r.nextInt(3));
            score = 50 + r.nextInt(50) + "";
            db.insertInfo("insert into test1 values(null,'" + name + "'," + score + ",'1949-11-3',2200,'英语')");
        }

        //db.selectInfo("select * from test1","id","name","score","birthday","money","dept");
        //get("pst", "hello", "world");
    }

    public static String Str(int num) {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        char[] cs = new char[num];
        Random r = new Random();
        String s = "";
        for (int i = 0; i < num; i++) {
            cs[i] = str.charAt(r.nextInt(str.length()));
            s = s + cs[i];
        }

        return s;
    }

    public static void get(String str, String... strings) {
        List<Map> list = new ArrayList<Map>();
        Map<String, String> map = new HashMap<String, String>();

    }

}

结果:数据库增条了1000条信息

猜你喜欢

转载自blog.csdn.net/weixin_42321963/article/details/82389336