java.lang.OutOfMemoryException:Java堆空间 [英] java.lang.OutOfMemoryException: java heap space
本文介绍了java.lang.OutOfMemoryException:Java堆空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在运行以下代码时,出现错误 java.lang.OutOfMemoryException:java堆空间
While running the following code i am getting the error java.lang.OutOfMemoryException : java heap space
我的代码是:
public class openofficeupdate {
String databaseurl="C:\\mydbdir\\location\\salesforce"; // Path of the base after renaming and extraction
openofficeupdate() throws ClassNotFoundException, SQLException{
System.out.println("Entered into constructor");
Connection connection=null;
Statement statement=null;
try{
Class c=openofficeclass();
System.out.println("Class name set");
Connection cntn=createConnection(databaseurl);
connection=cntn;
System.out.println("connection created");
Statement stmt=createStatement(cntn);
statement=stmt;
System.out.println("Statement created");
executeQueries(stmt);
System.out.println("Query executed");
closeStatement(stmt);
System.out.println("Statement closed");
closeConnection(cntn);
System.out.println("Connection closed");
}catch(Exception e){
System.out.println(e);
closeStatement(statement);
System.out.println("Statement closed");
closeConnection(connection);
System.out.println("Connection closed");
}
}
public static void main(String args[]) throws ClassNotFoundException, SQLException{
new openofficeupdate();
}
private Class openofficeclass() throws ClassNotFoundException {
return Class.forName("org.hsqldb.jdbcDriver");
}
private Connection createConnection(String databaseurl) throws SQLException{
return DriverManager.getConnection("jdbc:hsqldb:file:" +databaseurl,"sa","");
}
private Statement createStatement(Connection cntn) throws SQLException{
return cntn.createStatement();
}
private void closeStatement(Statement stmt) throws SQLException{
stmt.close();
}
private void closeConnection(Connection cntn) throws SQLException{
cntn.close();
}
private void executeQueries(Statement stmt) throws SQLException{
System.out.println("Going to execute query");
int status=stmt.executeUpdate("insert into \"Mobiles\" values(9874343210,123,'08:30:00','09:30:06')");
12','2010-12-14','c','Casula')");
System.out.println("Query executed with status "+status);
}
}
我正在使用NetBeans IDE ...那里有控制这种错误的选项吗?
I am using NetBeans IDE... Is there any option there to control this kind of errors?
推荐答案
在Netbeans 7.0中:
In Netbeans 7.0:
-
您可以右键单击该项目,然后选择
Properties
.
单击 Run
类别,然后将配置插入 VM Options
Click on Run
category and insert you configuration in VM Options
例如,按照您的情况,粘贴: -Xmx512m
(512Mb),如rm5248所建议
For instance, in your case, paste: -Xmx512m
(512Mb) as suggested by rm5248
You can read Playing with JVM / Java Heap Size for further information.
这篇关于java.lang.OutOfMemoryException:Java堆空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文