I am very new using jtds connection driver. I have written an application which reads around 2500 large xml's and makes SQL queries and run against SQL server. I have seen that when i reach a certain amount of xml my program run's out of memory. I checked my phd dump file in eclipse using memory analyzer and found that net.sourceforge.jtds.jdbc.cache.SimpleLRUCache is holding onto a lot of memory. I connect to SQL server once and keep the connection alive till i flush all my queries. Below is my code for running the queries against the server. I don't know how to gain an handle to net.sourceforge.jtds.jdbc.cache.SimpleLRUCache class since it has a clear method which i think might clear the cache. Again I am not very knowledgeable with jtds drivers. Can anyone help me solving this one?
public boolean runQueries(String query){
if (getConn() != null && query != null) {
Statement statement = null;
try {
long start = System.currentTimeMillis();
try {
if(log.isLoggable(Level.FINEST)){
log.finest("Processing: "+query);
}
statement = getConn().createStatement();
statement.executeUpdate(query);
} catch (Exception e) {
if(log.isLoggable(Level.FINEST)){
log.log(Level.SEVERE, "Failed to process query: "
+ query, e);
}else{
String reportQuery = query.length() > MAX_CHARS_DISPLAY ? query.substring(0,MAX_CHARS_DISPLAY)+"..." : query;
log.log(Level.SEVERE, "Failed to process query: "
+ reportQuery , e);
}
}finally{
if(statement != null){
try {
statement.close();
} catch (SQLException e) {
log.log(Level.SEVERE,"Failed to close statement: ",e);
}
}
}
long end = System.currentTimeMillis();
return true;
}finally{
if(statement != null){
try {
statement.close();
} catch (SQLException e) {
log.log(Level.SEVERE,"Failed to close statement: ",e);
}
}
}
}
return false;
}
The FAQ explains how to change the size of the statement cache by setting a lower value for maxStatements in the JDBC URL. If you are building very large statements, you may want to set that limit far below the default of 500. You also might want to look at some of the other memory settings there.