dbTalk Databases Forums  

R: java.lang.OutOfMemoryError - LONG (with test case)

mailing.database.mysql-java mailing.database.mysql-java


Discuss R: java.lang.OutOfMemoryError - LONG (with test case) in the mailing.database.mysql-java forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Andrea
 
Posts: n/a

Default R: java.lang.OutOfMemoryError - LONG (with test case) - 02-23-2006 , 05:59 AM






Try with

for (int j =3D 0; j <=3D 100; j++) {
sql =3D "SELECT * FROM " + TABLE_NAME + ";";
stmt =3D conn.createStatement();
ResultSet rs =3D stmt.executeQuery(sql);
while (rs.next()) {
rs.getString("col1");
}
rs.close();
stmt.close();=09
}

I think you must close ResultSet and Statement.

Andrea Sodomaco
www.sodomaco.it



-----Messaggio originale-----
Da: Przemyslaw Klein [mailto.klein (AT) ziaja (DOT) com]=20
Inviato: gioved=EC 23 febbraio 2006 12.48
A: java (AT) lists (DOT) mysql.com
Oggetto: java.lang.OutOfMemoryError - LONG (with test case)


Hi All.

This test case tries to perform following steps:
1. connect to database
2. create table with 9 columns - col1 int, col2 varchar(255), col3 text,

col4 int, col5 varchar(255), col6 text, col7 int, col8 varchar(255),=20
col9 text
3. populate it with 200 rows - same values=20
('1','2','3','4','5','6','7','8','9')
4. try to retrieve 'col1' from every row 300*100 times
5. disconnect from database

Unfortunately it throws java.lang.OutOfMemoryError during step 4. As you

can see, we don't store retrieved data, so we don't consume any memory.=20
We run this test under Borland OptimizeIt Profiler and ito shows that=20
99,9% memory consumes mysql connector.

MySQL server: mysql Ver 14.7 Distrib 4.1.10, for pc-linux-gnu (i686)
jdbc: mysql-connector-java-3.1.12-bin.jar

Thanks for any help,
Przemek

------------------------------------------------------------------------

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
* MySQL JDBC connector test. This test causes:<br>
* <code>Exception in thread "main" java.lang.OutOfMemoryError: Java=20
heap space</code>
*
* @author Oskar Sawicki
*
*/
public class MySQLTest {

private final static String DB_NAME =3D "test";

private final static String DB_USER =3D "root";

private final static String DB_PASSWD =3D "";

private final static String TABLE_NAME =3D "test";

/**
* Main method. Makes connection and executes testing query.
*
* @param args
* @throws SQLException
* @throws ClassNotFoundException
* @throws InstantiationException
* @throws IllegalAccessException
*/
public static void main(String[] args) throws SQLException,
ClassNotFoundException, InstantiationException,
IllegalAccessException {

String driver =3D "com.mysql.jdbc.Driver";
String url =3D "jdbc:mysql://localhost/" + DB_NAME + "?user=3D" =
+=20
DB_USER
+ "&password=3D" + DB_PASSWD
+ "&useUnicode=3Dtrue&characterEncoding=3Dlatin2 ";

Class.forName(driver).newInstance();

Connection conn =3D DriverManager.getConnection(url);

String sql =3D "drop table if exists " + TABLE_NAME + ";";
Statement stmt =3D conn.createStatement();
stmt.execute(sql);

sql =3D "CREATE TABLE "
+ TABLE_NAME
+ " (col1 int, col2 varchar(255), col3 text, col4 int,=20
col5 varchar(255), col6 text, col7 int, col8 varchar(255), col9 text)";
stmt =3D conn.createStatement();
stmt.execute(sql);

for (int i =3D 0; i <=3D 200; i++) {
sql =3D "insert into "
+ TABLE_NAME
+ " values ('1','2','3','4','5','6','7','8','9')";
stmt =3D conn.createStatement();
stmt.execute(sql);
}
for (int i =3D 0; i <=3D 300; i++) {
System.out.println("iteration: 100*" + i);
System.out.flush();

for (int j =3D 0; j <=3D 100; j++) {
sql =3D "SELECT * FROM " + TABLE_NAME + ";";
stmt =3D conn.createStatement();
ResultSet rs =3D stmt.executeQuery(sql);
while (rs.next()) {
rs.getString("col1");
}
}
}

conn.close();
}
}


--=20
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/java?unsub=3D...brujo (DOT) it


--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/java?unsub=3D...ie.nctu.edu.tw


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.