IDE Used:Netbeans 8.1.
Reading large data from MySQL database. Below is my code:
List outer=new ArrayList<String>();
List inner=new ArrayList<String>();
Connection con;
Statement stmt;
ResultSet rs;
ResultSetMetaData rsmd;
int columnNumber;
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","root","root");
stmt=con.createStatement();
rs=stmt.executeQuery("select * from mytable where srno<1000");
rsmd=rs.getMetaData();
columnNumber=rsmd.getColumnCount();
while(rs.next()){
for(int i=1;i<columnNumber;i++){
inner.add(rs.getString(i));
}
outer.add(inner);
}
System.out.println("\t" + outer);
rs.close();
con.close();
}catch(Exception e){
System.out.println(e);
}
I am getting error while running the code: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
I've tried to set vm options in properties>run>VM Options: -Xmx1024m
I am still getting the same error.How do I resolve it?
x bytesyou finish withx*43MB. If the average size of each column is 10 bytes you have 0,5GB in the heap. No way.