• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

mysql-Eclipse用JAVA连接Mysql 插入大量数据报错 Java heap space

mysql 搞代码 4年前 (2022-01-09) 22次浏览 已收录 0个评论

mysql大量数据java

public void Get_WayId_Ref_isWay() throws IOException
{

<code>    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+";    //用匹配<way id后面的数字    String regex_id="(?<=id=\")\\d+";    //读取整个文件信息    try {        Class.forName(driver).newInstance();        con=DriverManager.getConnection(url,user,pwd);        con.setAutoCommit(false);        int count=0;        int batchCount=1;        while((s=new StringBuffer(br.readLine()))!=null)        {            count++;            ArrayList tmp=new ArrayList();            //找出way类的信息            if(batchCount%100==0)            {                ps.clearBatch();            }            if(s.indexOf("0)                {                  //获得每一组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());                     //获得该wayid下的refid                     if(s.indexOf("0)                     {                         System.out.println("所在行数:"+count);                         Pattern p=Pattern.compile(regex_nd);                         Matcher m=p.matcher(s);                                if(m.find())                        {                            tmp.add(new StringBuffer(m.group()));                        }                     }                     //判断该way是否为道路                    if(s.indexOf("0||s.indexOf("0||s.indexOf("0)                    {                        isWay=new StringBuffer("true");                    }                }                 for(int i=0;i<tmp.size();i++)                 {                              if(isWay.toString().equals("true"))                        {                            batchCount++;                            StringBuffer sql1 = new StringBuffer();                            sql1.append("insert into test_wayid(wayid,id,isway) values(");                            sql1.append("'" +wayId+"'");                            sql1.append(", '"+tmp.get(i)+"', '"+"1');");                                                    ps=con.prepareStatement(sql1.toString());                            ps.addBatch();                        }                        if(isWay.toString().equals("false"))                        {                            batchCount++;                            StringBuffer sql1 = new StringBuffer();                            sql1.append("insert into test_wayid(wayid,id,isway) values(");                            sql1.append("'" +wayId+"'");                            sql1.append(", '"+tmp.get(i)+"', '"+"1');");</code>

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

<code>                        }                        ps.executeBatch();                        if(batchCount%100==0)                        {                            con.commit();                        }                    }                }        }        con.commit();    } catch (Excep<strong>本文来源gaodai#ma#com搞@代~码^网+</strong>tion e) {        e.printStackTrace();        // TODO: handle exception    }finally{        try {            if(ps!=null) ps.close();            if(con!=null) con.close();        } catch (Exception e2) {            e2.printStackTrace();        }    }    }</code>

报的错误是:
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)


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:mysql-Eclipse用JAVA连接Mysql 插入大量数据报错 Java heap space
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址