i am using the below code for creating the connection to database.

connectionURL = "jdbc:oracle:thin:@//testdsfsdfgs:1521/TEST";
conn = DriverManager.getConnection(connectionURL, userName,Password);

i want to set the transaction time out. How can i do that.

Please some one help.
Thanks in advance

Recommended Answers

All 5 Replies

Tranaction timeout means complete round of time from creating the connection-executing the queries-disconnecting.

You can use this: setQueryTimeout

If I get you right and you don't want to set it on a DB level; if so, you have to configure it base on what DBMS you're using.

Actually i have to execute one query which will take an average of 2sec. what ever time it takes for querying, i should end teh connection in 6 seconds.

Presumably you could start a java.util.Timer when you start the query, then when the Timer expires after 6 seconds its TimerTask could call Connection's abort method to terminate the connection (which in turn will abort the query with a SQLException). It's a bit crude, but should work.

Thanks for your reply.

As i could see only query level time out is sufficient.
If i can able to do it with oracle options in the connection URL or with Properties then fine. 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.