This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
Joined: Oct 13, 2002
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