When mysql-Eclipse connects to Mysql using JAVA and inserts a large amount of data, the error Javaheapspace is returned.

Source: Internet
Author: User
Terminate () throwsIOException {PreparedStatementpsnull; Connectionconnull; terminate (newFileReader (Path. path_read_beijing); StringBuffersnull; StringBufferwayIdnull; StringBufferisWay...

Public void Get_WayId_Ref_isWay () throws IOException
{

PreparedStatement ps = null; Connection con = null; BufferedReader br = new BufferedReader (new FileReader (Path. path_read_beijing); StringBuffer s = null; StringBuffer wayId = null; StringBuffer isWay = new StringBuffer ("false"); String regex_nd = "\ d +"; // Match
   
    
Tmp = new ArrayList
    
     
(); // Find the information of the way class if (batchCount % 100 = 0) {ps. clearBatch () ;}if (s. indexOf ("
     
      
0) {// Obtain each group of WayId Pattern p1 = Pattern. compile (regex_id); Matcher m1 = p1.matcher (s); if (m1.find () {wayId = new StringBuffer (m1.group ();} while (s. indexOf ("
     
    
   ") <= 0) {count ++; s = new StringBuffer (br. readLine (); // Obtain the refid if (s. indexOf ("
   
    
0) {System. out. println ("number of rows:" + count); Pattern p = Pattern. compile (regex_nd); Matcher m = p. matcher (s); if (m. find () {tmp. add (new StringBuffer (m. group () ;}}// determine whether the way is road if (s. indexOf ("
    
     
0 | s. indexOf ("
     
      
0 | s. indexOf ("
      
       
0) {isWay = new StringBuffer ("true") ;}} for (int I = 0; I
       
      
     
    
   

ps=con.prepareStatement(sql1.toString());
ps.addBatch();

                        }                        ps.executeBatch();                        if(batchCount%100==0)                        {                            con.commit();                        }                    }                }        }        con.commit();    } catch (Exception e) {        e.printStackTrace();        // TODO: handle exception    }finally{        try {            if(ps!=null) ps.close();            if(con!=null) con.close();        } catch (Exception e2) {            e2.printStackTrace();        }    }    }

The error message is:
Java. SQL. SQLException: java. lang. OutOfMemoryError: Java heap space
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 1055)
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 956)
At com. mysql. jdbc. SQLError. createSQLException (SQLError. java: 926)
At com. mysql. jdbc. Util. handleNewInstance (Util. java: 430)
At com. mysql. jdbc. PreparedStatement. getInstance (PreparedStatement. java: 561)
At com. mysql. jdbc. ConnectionImpl. clientPrepareStatement (ConnectionImpl. java: 1395)
At com. mysql. jdbc. ConnectionImpl. prepareStatement (ConnectionImpl. java: 4178)
At com. mysql. jdbc. ConnectionImpl. prepareStatement (ConnectionImpl. java: 4077)
At Wayid_To_ SQL .Get_Map_Line_beta.Get_WayId_Ref_isWay (Get_Map_Line_beta.java: 128)
At Wayid_To_ SQL .Get_Map_Line_beta.main (Get_Map_Line_beta.java: 35)

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.