Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I need help with this one

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
counter++;
}

}
catch ( Exception e)
{
throw new RuntimeException( "" + e);
}
finally
{
if ( statement!=null)
{
try
{
statement.close();
}
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
thanks
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic