9000 000 data randomly inserted in MySQL

Source: Internet
Author: User

 Packagequery;Importjava.sql.Connection;ImportJava.sql.DriverManager;ImportJava.sql.ResultSet;Importjava.sql.SQLException;Importjava.sql.Statement;ImportJava.util.Random;ImportJava.util.jar.Attributes.Name; Public classQuery { Public Static voidMain (string[] args) {//driver nameString Driver = "Com.mysql.jdbc.Driver"; //URL point to the database name to access 9millionString url = "Jdbc:mysql://127.0.0.1:3306/9million"; //user name when MySQL is configuredString user = "root"; //password for MySQL configurationString Password = ""; Try {            //Load DriverClass.forName (driver); //Continuous DatabaseConnection conn =drivermanager.getconnection (URL, user, password); if(!conn.isclosed ()) System.out.println ("Succeeded connecting to the database!"); //statement used to execute SQL statementsStatement Statement =conn.createstatement (); //the SQL statement to execute             for(inti= 0; I <= 9000 000; i + +) {String rdname= RandomString (8); intID =i; System.out.println (Rdname);
missing quotation marks will make an error, cannot find Collumn "ID" or "Rdname"
int can not be added, but the type of string must be added.
Low-level implementation under the study of available space String SQLL = "INSERT into TestData (id,name) VALUES ('"+id+"','"+rdname+"')";
Statement.execute (SQLL); } conn.close (); } Catch(ClassNotFoundException e) {System.out.println ("Sorry,can ' t find the driver!"); E.printstacktrace (); } Catch(SQLException e) {e.printstacktrace (); } Catch(Exception e) {e.printstacktrace (); } } /*** Generate random String **/ Private StaticRandom Randgen =NULL; Private Static Char[] Letters =NULL; Public Static FinalString RandomString (intlength) { if(Length < 1) { return NULL; } if(Randgen = =NULL) {Randgen=NewRandom ();//numbersandletters = ("0123456789abcdefghijklmnopqrstuvwxyz" +//"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"). ToCharArray ();Letters = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"). ToCharArray (); //numbersandletters = ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"). ToCharArray (); } Char[] Randbuffer =New Char[length]; for(inti=0; i<randbuffer.length; i++) {Randbuffer[i]= Letters[randgen.nextint (25)]; //Randbuffer[i] = Numbersandletters[randgen.nextint (+)]; } return NewString (Randbuffer); }}

9000 000 data randomly inserted in MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.