⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kfc.java.bak

📁 java chengxu database xiangguan
💻 BAK
字号:
import java.sql.*;
import oracle.jdbc.driver.*;
public class KFC  
{
	/* lastname for random selection */
	public static String lastname[] = {"张","王","周","曹","洪","陈","陆","黄","邓","倪",
						 "李","仇","郁","柏","赵","梁","许","徐","艾","金",
						 "朱","郭","范","毛","石","贾","顾","江","宋","邬",
						 "马","牛","杨","德","柳","刘","孙","温","纪","蓝",
						 "汪","高","谭","龚","何","华","霍","乔","姜","奖"};

	/* singlename for random selection */
	public static String[] singlename = {"烨","平","华","佶","菁","婧","竫","树","木","草",
						  "棉","月","沙","丘","米","等","界","地","山","和",
						  "村","存","牙","池","瘿","影","绿","丝","谜","湖",
						  "灵","以","宜","迦","玳","瑁","午","坡","东","苏",
		                  "京","采","戒","一","二","三","四","五","六","七",
						  "八","九","十","白","千","万","已","亿","单","双",
						  "牡","茉","槿","思","瓶","子","鱼","雨","荔","丹",
		                  "水","土","琅","浮","成","往","冠","邪","皮","品",
						  "小","大","勇","是","谁","柳","西","南","贺","之",
						  "指","那","味","旯","墨","莫","津","觅","寻","泪",
						  "极","否","泰","来","碘","钙","晴","阴","黑","岸",
						  "爱","恨","群","临","玉","耳","兰","灰","丸","菜",
		                  "愁","闷","煮","炖","有","锌","怡","雅","零","霖",
						  "它","难","度","变","别","清","荤","酥","仑","路",
						  "腊","问","缓","暖","凉","冷","速","些","很","非",
		                  "透","车","酒","杯","桉","岛","后","羽","项","飞",
		                  "了","油","听","倾","淳","朴","跑","布","并","下",
		                  "桦","科","蓝","兹","梓","俗","庸","莲","核","陶",
		                  "乡","象","态","近","远","摇","尧","银","铁","策",
		                  "查","贞","快","苦","田","轶","楠","菌","棒","胖"};

	/* city for random selection */
	public static String city[] = {"上海","北京","天津","杭州","扬州","烟台","长春","沈阳","丽江","桂林",
		             "三亚","成都","西宁","伊犁","拉萨","银川","武汉","大连","重庆","长沙"};

	/* occupation for random selection */
	public static String[] occupation = {"学生","会计","运动员","经理","财务","销售员","演员","歌手","清洁工","农民",
		                   "医生","教师","工人","军人","建筑师","画家","作家","宇航员","科学家","主持人",};


	

	/* create random name of customer */
	public static String random_name()
	{
		String lastnm = lastname[(int)(Math.random()*50)];
		int namelen = (int)(Math.random()*2);
		if (namelen==1)
		{
			return lastnm+singlename[(int)(Math.random()*200)];
		}
		else 
			return lastnm+singlename[(int)(Math.random()*200)]+singlename[(int)(Math.random()*200)];
	}

	/* create random city */
	public static String random_city()
	{
		return city[(int)(Math.random()*20)];
	}

	/* create random occupation */
	public static String random_occupation()
	{
		return occupation[(int)(Math.random()*20)];
	}

	/* create random idcode of customer */
	public static String random_idcode()
	{
		String str = "";
		for (int i=0; i<18; i++)
		{
			str += (int)(Math.random()*10);
		}
		
		return str;
	}

	/* create random gender of customer */
	public static String random_gender()
	{
		int sex = (int)(Math.random()*2);
		if (sex==0)
		{
			return "男";
		}
		return "女";
	}

	/* create random age of customer */
	public static int random_age()
	{
		return ((int)(Math.random()*60)+1);
	}

    /* create random date for order */
	public static String random_date()
	{
		int year = (int)(Math.random()*15)+1990;
		int month = (int)(Math.random()*12)+1;
		int day = 0;
		if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
		{
			day = (int)(Math.random()*31)+1;
		}
		else if (month==2)
		{
			day = (int)(Math.random()*28)+1;
		}
		else 
			day = (int)(Math.random()*30)+1;

		return day+"-"+month+"月-"+year;
	}

	/* create random order type */
	public static String random_order_type()
	{
		int ran = (int)(Math.random()*2);
		if (ran==0)
		{
			return "堂吃";
		}
		else
			return "外卖";
	}

	public static void main(String[] args) 
	{
		try
		{
			/* connect to database */
			Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
			String url="jdbc:oracle:thin:@localhost:1521:myoracle";
			//orcl为数据库的SID
			String user="system";
			String password="manager";

			Connection conn= DriverManager.getConnection(url,user,password);

			/* insert into KFC_CHAINSTORELIST 800 infomation 
			String store = "insert into KFC_CHAINSTORELIST values(?,?,?)";
			PreparedStatement pstm_store=conn.prepareStatement(store);

			for (int i=0; i<800; i++)
				
			{
				pstm_store.setInt(1,i);
				String thecity = random_city();
				pstm_store.setString(2,thecity+i);
				pstm_store.setString(3,thecity);
				
				pstm_store.addBatch();
			}
			pstm_store.executeBatch();*/

			/* insert into KFC_CUSTOMERLIST 100000 infomation 
			String customer = "insert into KFC_CUSTOMERLIST values(?,?,?,?,?,?)";
			PreparedStatement pstm_customer=conn.prepareStatement(customer);
			for (int i=0; i<100000; i++)
			{
				pstm_customer.setInt(1,i);
				pstm_customer.setString(2,random_name());
				pstm_customer.setString(3,random_idcode());
				pstm_customer.setString(4,random_gender());
				pstm_customer.setInt(5,random_age());
				pstm_customer.setString(6,random_occupation());
				
				pstm_customer.addBatch();
			}
			pstm_customer.executeBatch();*/

			/* insert into KFC_ORDER 2000000 infomation */
			String order = "insert into KFC_ORDER values(?,?,?,?,?)";
			PreparedStatement pstm_order=conn.prepareStatement(order);
//			System.out.println(times);
			String order_item = "insert into KFC_ORDERITEMS values(?,?,?,?)";
			PreparedStatement pstm_order_item=conn.prepareStatement(order_item);
			int i=0;
			while (i<2000000)
			{

				pstm_order.setInt(1,i);
				pstm_order.setString(2,random_date());
				pstm_order.setInt(3,(int)(Math.random()*800));
				pstm_order.setInt(4,(int)(Math.random()*100000));
				pstm_order.setString(5,random_order_type());

				pstm_order.addBatch();
				
			
				/* insert into KFC_ORDERITEMS 1~5 infomation for each KFC_ORDER */
				int times = (int)(Math.random()*5)+1;
				
				
				for (int j=0; j<times; j++)
				{
					//System.out.println(times+"AAAAAA");
					pstm_order_item.setString(1,i+"-"+j);
					pstm_order_item.setInt(2,i);
					pstm_order_item.setInt(3,(int)(Math.random()*20));
					pstm_order_item.setInt(4,((int)(Math.random()*100)+1));

					pstm_order_item.addBatch();
				}
				if(i%10000==0)			
				{
					pstm_order.executeBatch();
					pstm_order.clearBatch();
					pstm_order_item.executeBatch();
					pstm_order_item.clearBatch();
				}
				i++;
				
			}
			pstm_order.executeBatch();
			pstm_order.clearBatch();
			pstm_order_item.executeBatch();
			pstm_order_item.clearBatch();
			

			
			System.out.println(random_date());
			System.out.println(random_order_type());
		}
		catch(Exception e)
		{
			System.err.println(e);
		}
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -