JAVA Implementation Data import Phoenix

Source: Internet
Author: User

The jar packages that need to be imported are:

Implementation code:

 Packagecn.test;Importjava.sql.Connection;ImportJava.sql.DriverManager;Importjava.sql.SQLException;Importjava.sql.Statement;ImportJava.util.Random; Public classPhoenixtest { Public Static voidInsertdatas () {Statement stmt;        Connection con; String ItemID= Getitemid (10 ); String ItemName= Getitemname (10); floatPrice = (float) 0.1; Try{con= Drivermanager.getconnection ("jdbc:phoenix:node11:2181" ); stmt=con.createstatement (); System.out.println ("Content success ..."); //stmt.executeupdate ("CREATE TABLE Test (MyKey integer NOT null primary key, MyColumn varchar)");Stmt.executeupdate ("CREATE table items (ItemID varchar NOT NULL primary key,itemname varchar null,price FLOAT NULL");  for(inti = 0; i < 1000; i++)//How much data needs to be imported to modify itself, if the volume of data is larger requires 500 or 1000 to be submitted once, or a timed commit, the next time you modify the code {stmt.executeupdate ("Upsert into items values ('" + ItemID + "', '" + ItemName + "', '" + price++ + "')" );            } con.commit ();        Con.close (); }        Catch(SQLException e) {e.printstacktrace (); }    }    /*** Generate random numbers as Getitemid * *@return     */     Public StaticString Getitemid (intN) {String val= ""; Random Random=NewRandom ();  for(inti = 0; I < n; i++) {String str= Random.nextint (2)% 2 = = 0? "Num": "Char"; if("Char". Equalsignorecase (str)) { //Generate Letters                intNextint = Random.nextint (2)% 2 = = 0? 65:97; //System.out.println (nextint + "!!!!"); 1,0,1,1,1,0,0Val + = (Char) (Nextint + Random.nextint (26 ) ); }            Else if("Num". Equalsignorecase (str)) { //Generate numbersVal + = string.valueof (Random.nextint (10 ) ); }        }        returnVal; }    /*** Production of ItemName random functions *@paramlength *@return     */     Public StaticString Getitemname (intlength) {String base= "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; Random Random=NewRandom (); StringBuffer SB=NewStringBuffer ();  for(inti = 0; i < length; i++ )        {            intNumber =Random.nextint (Base.length ());        Sb.append (Base.charat (number)); }        returnsb.tostring (); }     Public Static voidMain (string[] args) {insertdatas (); }}

JAVA Implementation Data import Phoenix

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.