Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-06 09:44:43
Original
1904 people have browsed it

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=\" try class.forname con="DriverManager.getConnection(url,user,pwd);" con.setautocommit int count="0;" batchcount="1;" while stringbuffer arraylist> tmp=new ArrayList<stringbuffer>();            //找出way类的信息            if(batchCount%100==0)            {                ps.clearBatch();            }            if(s.indexOf("<way>0)                {                  //获得每一组WayId                  Pattern p1=Pattern.compile(regex_id);                  Matcher m1=p1.matcher(s);                  if(m1.find())                  {                      wayId=new StringBuffer(m1.group());                  }                  while (s.indexOf("</way>") 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("<tag k='\"highway\"")'>0||s.indexOf("<tag k='\"cycleway\"")'>0||s.indexOf("<tag k='\"bridge\"")'>0)                    {                        isWay=new StringBuffer("true");                    }                }                 for(int i=0;i<tmp.size if batchcount stringbuffer sql1="new" sql1.append into test_wayid values ps="con.prepareStatement(sql1.toString());" ps.addbatch></tmp.size></tag></tag></tag></stringbuffer></way></code>
Copy after login

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

<code>                        }                        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();        }    }    }</code>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template