Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing a query time-out

 
Claudio Gualberto
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to implement a query execute time-out in a Servlet using JDBC.
The Servlet class throws an Thread for each query request, and waits for it's finish in a regular time. If ocurs a time-out, the main Thread interrupts the query Thread and returns an error to the client.
The problem is, what should i make with the Connection object ? ( it came from an connection pool ). If i close it, i should replace it on the pool with an just created connection. If i dont, the process in the RDBMS remains processing and slowing down the rest of the queries requests( in case of queries without WHERE clausule).
How can i quit an process of query executing with the underlying database in a clearly way.
Thanks.
Claudio Gualberto.
 
Tina Coleman
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haven't done this before, but thought I'd do some hunting. The java.sql.Statement interface has a method called cancel(), which "Cancels this Statement object if both the DBMS and driver support aborting an SQL statement. This method can be used by one thread to cancel a statement that is being executed by another thread". Assuming your DBMS and driver support canceling a statement, looks like exactly what you're looking for.
 
Claudio Gualberto
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Tina
You gave me a great idea, that is:
"what if i tried to find something at the Sun's documentation ?" ... it worked !!
That's what i found :
-----From Sun's documentation-----------
public void setQueryTimeout(int seconds)
throws SQLException
Sets the number of seconds the driver will wait for a Statement object to execute to the given number of seconds. If the limit is exceeded, an SQLException is thrown.
Parameters:
seconds - the new query timeout limit in seconds; zero means unlimited
Throws:
SQLException - if a database access error occurs
--------------------------------------------
you saved a lot of my time, thanks.
[]'s
Claudio Gualberto
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic