Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes How to write a query that takes more than 2 minutes to execute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to write a query that takes more than 2 minutes to execute " Watch "How to write a query that takes more than 2 minutes to execute " New topic
Author

How to write a query that takes more than 2 minutes to execute

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi ,

I am writing a small program for Testing purpose , in that my requirement is to write a query that takes more than 2 minutes to execute .Right now i have only a small Table called as "Users" with very less data .

Please let me know how can i achieve this thing ??

Thanks .


Save India From Corruption - Anna Hazare.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9963
    
163

I don't think this is related to EJBs. Can you explain a bit more before we move it to an appropriate forum?

[My Blog] [JavaRanch Journal]
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Basically i am testing as that ,, if the query takes more than 2 Minutes to execute , i need to stop executing it and display an Error Page in JSP (J2EE )

So please tell me , how can i achieve this . Thanks in advance .
how can i use

dbms_lock.sleep(120) with a basic query as "Select Names from Users" .
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

How do you stop it? The only dependable way I know is to implement query timeouts in the database itself (particularly as you appear to be using Oracle) - in which case why test it?

If you want to have the client try to cancel a long running query (which might not work) you could test it by writing a query that opens a cursor that loops forever.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Can you create stored procedures? If so, just write an infinite loop in there:
That should work.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bill Karwin
author
Ranch Hand

Joined: Aug 02, 2010
Posts: 32
What brand of database is this? (MySQL, Oracle, Microsoft SQL Server, etc.)

In MySQL, you can do: SELECT SLEEP(180) to make a query that take three minutes.

If you are using another brand of database, perhaps it has a similar function.


Bill Karwin is the author of SQL Antipatterns: Avoiding the Pitfalls of Database Programming
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Ravi wrote:
how can i use

dbms_lock.sleep(120) with a basic query as "Select Names from Users" .


You can wrap dbms_lock.sleep in a function:
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

This is the wrong approach to take.

Your goal is to test the response of a query taking too long--don't actually *make* the query, plug in a service implementation that simulates a long-running query.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to write a query that takes more than 2 minutes to execute
 
Similar Threads
how to compile single java file - to avoid building the entire project
EJB Query not executed fast
setQueryTimeout not working
paging (but not really) a SELECT statement via JDBC
threads and struts