Re: Don't use Connector/J 3.1 with Mysql 4.1.x
Posted by: Daniel Pereira
Date: February 28, 2005 04:54AM

Hi,
I think why you have problems upgrading your database.

I did a litle program in java which makes queries to the database. Above is an example:

private void timer2OnTime(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String query="";int rvr21=0;
Statement stmt=null;
ResultSet result=null;
Connection con_bdee;

// System.out.println("TIMER2:START");
for(int i=0;i<100000;i++){
// METEO (rvr21)
try {
query="SELECT `value` FROM `tblMeteo` WHERE `name`='rvr21'";
con_bdee=conn.getConnectionBdee();
stmt = con_bdee.createStatement();
result = stmt.executeQuery(query);
result.next();
rvr21=result.getInt(1);

} catch(SQLException ex) {
System.out.println("TIMER2:SQLException:("+query+")"+ex.getMessage());
} catch(Exception xx){
System.out.println("TIMER2:EXCEPCÇÂO: BEGIN");
xx.printStackTrace();
System.out.println("TIMER2:EXCEPCÇÂO: END");
}

}
}

Basically it make queries to the database, this method is running on timer (thread) with 500ms of interval, and i did another timer but with another query to another database. This program runs two threads at the same time.

When i run the program with the Connector/J 3.1.17 the memory of this program grows until it reaches the maximum memory (64Megas) and write "java.lang.OutOfMemory"

When i run the program with Connector/J 3.0.16 the memory stablizes and it didn't grows.

Reading again the documentation of the Connector, they recommended closing the statement and resultset of all queries. So, i append the following code to the try statement of the queries.

finally{
if(result!=null){
try{ result.close();}
catch(SQLException ex){ /*Nothing to do */ }
}
if(stmt!=null){
try{ stmt.close();}
catch(SQLException ex){ /*Nothing to do */ }
}
}

Using the Connector/J 3.1.17 the memory didn't grow.

Conclusion you must close all Statement if you want to use the version 3.1.17 of the Connector.

Note: If the resultSet isn't close the memory doesn't grow.
Note: Mysql 4.1.10 used


Is this a bug?
There is any way to prevent this wrong programing like the Connector/J 3.0.16(Closes automaticly the Statements cretated)?

I think, the crashes of the Dimitry program is a because a leak of memory. The queires i made to the database don't close the statements.

Now i'm using the Connector/3.0.16 and i have until now no problems

Best regards,
Daniel Pereira

Options: ReplyQuote


Subject
Written By
Posted
Re: Don't use Connector/J 3.1 with Mysql 4.1.x
February 28, 2005 04:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.