too many connections

We have an application written some years ago. The hosters, moving to a 2003 server found that the app times out while it's building a lookup table.

According to them its the following bit of code that's responsible.

Recordset donorIDs = null;

try {

donorIDs = objConn.execute("SELECT DonorID FROM Donors ORDER BY DonorID");

while (!donorIDs.getEOF()) {

String donorID = donorIDs.getField("DonorID").getString();

String sql="INSERT INTO DonorLookup (DonorID, HashValue) " +

"VALUES (" + donorID + ",\"" + getHashValue(donorID) + "\")";

objConn.execute(sql);

donorIDs.moveNext();

}

}

This is their comment about it:

In particular its objConn.execute, which almost opens a new connection everytime its run. Its ironic but if the code was changed to a Recordset and the loop created a new item in the recordset this would only use 1 connection and would work fine ?not 100% sure about this but its something I would try if I had the correct compiler.

I say the system 慳lmost?opens a new connection, it opens a new connection if the SQL Server isn抰 given time to complete the task.

Could anyone help with an alternative method, a CommandObject has been suggested as well, that would get rid of this connection 'overload'.

Not being a Java developer myself I have to ask, once the alternative snippet is supplied, how can I incorporate it into the compiled java class?

Thanks in advance

JV

[1515 byte] By [johnvaja] at [2007-11-26 17:39:38]
# 1
If understand this right: Opening a new connection for each line of data?This looks bad. Can the objConn object not be rewritten? Or something else used?Is connection pooling being used? I think some coding changes might be necessary.
zadoka at 2007-7-9 0:07:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
I agree it is bad. Question is, is it possible to rewrite just this snippet using standard classes, without rewriting any other classes in the code, so that a new connection isn't being opened for each record in the table.
johnvaja at 2007-7-9 0:07:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

> I agree it is bad. Question is, is it possible to

> rewrite just this snippet using standard classes,

> without rewriting any other classes in the code, so

> that a new connection isn't being opened for each

> record in the table.

Yes. I am not sure what the class of objConn does but you need to do the same, except not hold open so many connections.

zadoka at 2007-7-9 0:07:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...