java 链接mysql 产生500W数据模拟生成环境

java 插入数据到mysql 通过sqoop 导入到hive 中,kylin模拟见cube 时间和 数据膨胀率 kylin 数据插入到 HBase

Kylin

HBase 1.1.3

Hive 1.2.1

Hadoop 2.5.1


create table infoagetime(
prod_name char(10),
prod_id SMALLINT,
ods_date DATE
)

数据格式

oPmgBZxldW    75    2016-09-04
WSSAnnZrNy    57    2016-09-09


本人Java水平有限,大家自行改善,尤其是批量插入mysql语句


另工程中需要导入 mysql jar :   mysql-connector-java-5.1.6.jar

V2

package com.wubaiwan.instmysql;import java.io.File;
import java.io.FileOutputStream;
import java.sql.DriverManager;
import java.util.Random;public class YiBaiWan {public static String getRandomString(int length) { // length表示生成字符串的长度String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";Random random = new Random();StringBuffer sb = new StringBuffer();for (int i = 0; i < length; i++) {int number = random.nextInt(base.length());sb.append(base.charAt(number));}return sb.toString();}public static final String url = "jdbc:mysql://192.168.184.168/hive2";public static final String name = "com.mysql.jdbc.Driver";public static final String user = "root";public static final String password = "123";public static java.sql.Connection conn = null;public static java.sql.PreparedStatement pst = null;static FileOutputStream out = null;public static void main(String args[]) {try {Class.forName(name);conn = DriverManager.getConnection(url, user, password);// 获取连接conn.setAutoCommit(false);} catch (Exception e1) {// TODO Auto-generated catch blocke1.printStackTrace();} // 指定连接类型Random random = new Random();// int k = random.nextInt();// System.out.println(k);int x = 0;try {out = new FileOutputStream(new File("D:/mysql.txt"));String sql = "insert into infoagetime(prod_name,prod_id,ods_date) values(?,?,?)";// System.out.println(sql);pst = conn.prepareStatement(sql);while (x < 5000000) {// System.out.println((int)(Math.random()*100));// System.out.println(getRandomString(10) + ',' +// (int)(Math.random()*100));// String k = getRandomString(10) + ',' +// (int)(Math.random()*100 )+ ','+ "2016-09-0" +// (int)(random.nextInt(9)%9 + 1)+"\r\n" ;// System.out.println(k);// out.write(k.getBytes());pst.setString(1, getRandomString(10));pst.setInt(2, (int) (Math.random() * 100));pst.setString(3, "2016-09-0" + (int) (random.nextInt(9) % 9 + 1));pst.addBatch();if (x % 1000 == 0) {pst.executeBatch();//pst.executeUpdate(arg0)}x++;}System.out.println("Commit");pst.executeBatch();conn.commit();out.close();conn.close();pst.close();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{}}}



======================================

V1  这个版本会有java memory 异常

package com.wubaiwan.instmysql;import java.io.File;  
import java.io.FileOutputStream;
import java.sql.DriverManager;
import java.util.Random;public class YiBaiWan {  public static String getRandomString(int length) { //length表示生成字符串的长度      String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";         Random random = new Random();         StringBuffer sb = new StringBuffer();         for (int i = 0; i < length; i++) {         int number = random.nextInt(base.length());         sb.append(base.charAt(number));         }         return sb.toString();         }    public static final String url = "jdbc:mysql://192.168.184.168/hive2";    public static final String name = "com.mysql.jdbc.Driver";    public static final String user = "root";    public static final String password = "123";    public static java.sql.Connection conn = null;    public static java.sql.PreparedStatement pst = null;    public static void main(String args[]){  try {Class.forName(name);conn = DriverManager.getConnection(url, user, password);//获取连接 } catch (Exception e1) {// TODO Auto-generated catch blocke1.printStackTrace();}//指定连接类型   FileOutputStream out = null;     Random random = new Random();  //int k = random.nextInt();  //System.out.println(k);  int x = 0;  try {  out = new FileOutputStream(new File("D:/mysql.txt"));  while(x <5000000){  //System.out.println((int)(Math.random()*100));  //System.out.println(getRandomString(10) + ',' + (int)(Math.random()*100));  //String k = getRandomString(10) + ',' + (int)(Math.random()*100 )+ ','+ "2016-09-0" + (int)(random.nextInt(9)%9 + 1)+"\r\n" ;  //System.out.println(k);  //out.write(k.getBytes());  String sql = "insert into infoagetime(prod_name,prod_id,ods_date) values('"+getRandomString(10)+ "',"+(int)(Math.random()*100 )+","+ "'2016-09-0" + (int)(random.nextInt(9)%9 + 1) + "')"   ;//System.out.println(sql);pst = conn.prepareStatement(sql);  pst.executeUpdate();  if(x%10000 == 0 ) {System.out.println("Commit");conn.commit();}x++;  }   out.close();    conn.close();   pst.close();  }catch (Exception e) {  // TODO Auto-generated catch block  e.printStackTrace();  }  }  }  


转载于:https://www.cnblogs.com/TendToBigData/p/10501376.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/254463.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

中本聪研究所创始人对Core的发展方向感到厌恶

在本月&#xff0c;中本聪研究所&#xff08;Satoshi Nakamoto Institute&#xff09;的联合创始人Daniel Krawisz离开了该研究所&#xff0c;原因是Daniel觉得SNI社区逐渐变得让他无法忍受&#xff0c;甚至感到厌恶。Daniel发表在SNI上的大量文章被删除&#xff0c;有关于比特…

BZOJ 1026 [SCOI2009]windy数

1026: [SCOI2009]windy数 Description windy定义了一种windy数。不含前导零且相邻两个数字之差至少为2的正整数被称为windy数。 windy想知道&#xff0c;在A和B之间&#xff0c;包括A和B&#xff0c;总共有多少个windy数&#xff1f; Input 包含两个整数&#xff0c;A B。 Outp…

不连续区域的拟合

如下图&#xff0c;需要把图中4个半圆分别连接起来 我试过closing 和 dilation&#xff0c;下图中后三个还可以连接起来&#xff0c; 但是第一个因为不连续地方较长&#xff0c;如果增大closing的值&#xff0c;会导致其它点 出现过度畸形。 有没有能连接相邻选区的方法&#…

X264码率控制流程分析 (转)

二、编码器机能20钟头前  码率节制的意见常识&#xff1a;   码率节制的目的以及意义&#xff1a;   图象通讯中码率节制的目的&#xff1a;路程经过过程调治编码参量&#xff0c;节制单元时间内的编码视频文件流的数值量&#xff0c;以使 ... 二、编码器机能20钟头前码率…

SPSS输出的结果都要写到文章中吗

SPSS输出的结果都要写到文章中吗 经常有人问到&#xff0c;SPSS输出的结果都要写到文章中吗&#xff1f;文章中应该写什么呢&#xff1f;比如&#xff0c;均值、中位数、众数、标准差、百分位数、最小值、最大值等等&#xff0c;都要出现在文章中吗&#xff1f;洋洋洒洒那么多&…

php Closure 类型

2019独角兽企业重金招聘Python工程师标准>>> <?php /*** Closure 理解* 匿名函数&#xff08;Anonymous functions&#xff09;&#xff0c;* 也叫闭包函数&#xff08;closures&#xff09;* Closure 是匿名函数的php中的称呼*/// 创建一个Closure$func funct…

ftk学习记(label篇)

【 声明&#xff1a;版权全部&#xff0c;欢迎转载&#xff0c;请勿用于商业用途。 联系信箱&#xff1a;feixiaoxing 163.com】还是接着上面的一篇博文。之前以前答应过大家&#xff0c;让大家看一下最简单的ftk程序是怎么执行的。所以&#xff0c;这里我们上传一下图片。由于…

扇形特征点提取

处理要求 分别找出扇形左上角&#xff0c;左下角&#xff0c;右上角&#xff0c;右下角&#xff0c;最高点&#xff0c;下面弓形最高点 原图 halcon 处理程序 read_image (Image14208259e49d7b1cf7c544, 544.bmp) rgb1_to_gray (Image14208259e49d7b1cf7c544, GrayImage) t…

集成显卡与独立显卡的区别

集成的显卡不带有显存&#xff0c;使用系统的一部分主内存作为显存&#xff0c;显卡的数量一般是根据需要自然动态调整。显然&#xff0c;使用集成显卡运行需要大量占用显存的程序&#xff0c;对整个系统的影响比较明显&#xff0c;此外系统内存的频率通常比独立的显存度低很多…

[ CodeVS冲杯之路 ] P3116

不充钱&#xff0c;你怎么AC&#xff1f; 题目&#xff1a;http://codevs.cn/problem/3116/ 基础的高精度加法&#xff0c;注意一下两个数长短不一和答案第一位的处理即可&#xff0c;当然也可以用压位的方法做 1 #include<cstdio>2 #include<cstdlib>3 #include&l…

邮槽

邮槽是基于广播通信体系设计出来的&#xff0c;采用无连接的不可靠的数据传输&#xff1b;邮槽是一种一对一或一对多的单向通信机制&#xff0c;创建邮槽的服务器进程读取数据&#xff0c;打开邮槽的客户机进程写入数据&#xff1b;为保证邮槽在各种Windows平台下都能正常工作&…

Android Studio maven-metadata.xml 卡着不动原因和解决方法

头一天好好的&#xff0c;第二天就卡着了。 一直在这个地方不动&#xff0c;如果停止就会报 Error:Could not run build action using Gradle distribution ‘https://services.gradle.org/distributions/gradle-4.1-all.zip‘. 所以直接就去看了下链接&#xff1a;https://dl.…

h.264 SODB RBSP EBSP的区别

SODB 数据比特串&#xff0d;&#xff0d;&#xff1e;最原始的编码数据 RBSP 原始字节序列载荷&#xff0d;&#xff0d;&#xff1e;在SODB的后面填加了结尾比特&#xff08;RBSP trailing bits 一个bit“1”&#xff09;若干比特“0”,以便字节对齐。 EBSP 扩展字节序…

C# 控件置于最顶层、最底层、隐藏、显示

控件置于最顶层、最底层 pictureBox1.BringToFront();//将控件放置所有控件最前端 pictureBox1.SendToBack();//将控件放置所有控件最底端 控件隐藏、显示 pictureBox1.Visible true;//显示 pictureBox1.Visible false;//隐藏

习题8.3.(1)

1 #include <iostream>2 #include <iomanip>3 #include <cstdlib>4 using namespace std;5 6 #define OK 17 #define ERROR 08 #define OVERFLOW -29 typedef int Status; //Status 是函数返回值类型&#xff0c;其值是函数结果状态代码。 10 11 typedef in…

python:实例化configparser模块读写配置文件

之前的博客介绍过利用python的configparser模块读写配置文件的基础用法&#xff0c;这篇博客&#xff0c;介绍下如何实例化&#xff0c;方便作为公共类调用。 实例化的好处有很多&#xff0c;既方便调用&#xff0c;又降低了脚本的维护成本&#xff0c;而且提高了代码的可读性。…

halcon 圆环类缺陷检测的一种方法(极坐标变换法)

目录简介极坐标变换定义原理Halcon中的极坐标变换1、polar_trans_image_ext算子用法与参数剖析2、polar_trans_region_inv算子用法与参数剖析圆环类缺陷检测思路与步骤Halcon实例实例简介程序解读思路剖析应用实例1项目介绍处理程序处理效果应用实例2项目介绍处理程序处理效果简…

linux的mount命令详解

linux下挂载&#xff08;mount&#xff09;光盘镜像文件、移动硬盘、U盘、Windows和NFS网络共享 linux是一个优秀的开放源码的操作系统&#xff0c;可以运行在大到巨型小到掌上型各类计算机系统上&#xff0c;随着 linux系统的日渐成熟和稳定以及它开放源代码特有的优越性&…

cat命令

$ cat file 显示文件中的内容$ cat -n file 可以显示文件的内容和行号$ cat -b file -b与-n类似&#xff0c;但只标识非空白行的行号$ cat -e file 在每一行的末尾显示“$”字符&#xff0c;在需要将多行内容转换成一行时非常有用。$ cat 只是接收标准输入的内容并显示&#xf…

生成验证码的流程分析.

浏览器解析页面, 携带uuid向服务器发送请求获取图片, 服务器生成图片验证码, 返回图片本身给浏览器, 客户端根据图片输入验证码内容, 把输入的内容发送给服务器, 服务器对比输入的验证码是否正确.根据前端传入的uuid从redis中获取唯一图片验证码名称. 服务器: 图片, 图片内容…