File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes I need help with this one Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "I need help with this one" Watch "I need help with this one" New topic

I need help with this one

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi all:
I have this code, which was written by some other programmer.
Context ic = new InitialContext();
DataSource dataSource = (DataSource) ic.lookup(Constants.blah);
conn = dataSource.getConnection();
for ( int i = 0; i < lookupIdsToInsert.length; i++ )
String call = "{Call " + insertProcedureName + "(?,?)}";
statement = conn.prepareCall( call );
statement.setString(1, providerId);
statement.setString(2, lookupIdsToInsert[i] );
statement.execute();//error is thrown here

catch ( Exception e)
throw new RuntimeException( "" + e);
if ( statement!=null)
catch ( java.sql.SQLException se)
{ }
if ( conn!=null )
try{ conn.close();
catch ( Exception e2)
{ return counter;
the previous code throw this errors:Connection reset by peer: JVM_recv in
socket input stream read, Failed to close statement
[Microsoft][SQLServer 2000 Driver for JDBC]Object has been closed.
at line statement.execute() this line throw the errors.
it is running on SQL2k
any idea what is going on

SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Does the error get thrown the first time through the loop, or after several iterations? One potential problem is that you are creating multiple "Statement" instances inside of the "for(...)" loop, but you are only closing one in the "finally" clause.
This is a case where you'll need to close the statement inside of the loop (do it inside of a separate try/catch block). You may be running out of resources if you create too many statement instances.
I agree. Here's the link:
subject: I need help with this one
It's not a secret anymore!