[groovy-user] SQL, set timeout for query

367 views
Skip to first unread message

citron

unread,
Jan 19, 2010, 10:38:22 AM1/19/10
to us...@groovy.codehaus.org

I am running a query that sometimes can take too long time
Is it possible to set a time out so the execution stops with no values
returned?

import groovy.sql.Sql

sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:XE", "user",
"pwd", "oracle.jdbc.driver.OracleDriver")

sql.eachRow("select * from someTable", {
println it
} ).setTimeout(15000) // set timeout for query to 15 seconds ??


Thanks!
--
View this message in context: http://old.nabble.com/SQL%2C-set-timeout-for-query-tp27227674p27227674.html
Sent from the groovy - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Merlyn Albery-Speyer

unread,
Jan 26, 2010, 10:04:18 PM1/26/10
to us...@groovy.codehaus.org
It doesn't appear so, no. You could setQueryTimeout if you can get
access to the Statement. Enforcing the timeout though is up to the
database implementation so it's not guaranteed. The Oracle way to do
this is at a user profile level by assigning a CPU time limit. I'm
curious as to why you want this. Do you not have control over the sql
you are executing?

mcamilo

unread,
Jan 27, 2010, 3:55:16 PM1/27/10
to us...@groovy.codehaus.org


Merlyn Albery-Speyer wrote:
>
> It doesn't appear so, no. You could setQueryTimeout if you can get
> access to the Statement.
>

I believe the correct way to do this is as follows:


sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:XE", "user",
"pwd", "oracle.jdbc.driver.OracleDriver")

sql.withStatement {
stmt -> stmt.queryTimeout = 10
}

sql.eachRow("select * from someTable", {
println it
} )


--
View this message in context: http://old.nabble.com/SQL%2C-set-timeout-for-query-tp27227674p27346658.html

Reply all
Reply to author
Forward
0 new messages