How to set JDBC connection timeout?

R

RC

The Subject says its all.

I can't do

DriverManager dm = new DriverManager();

But I can do

Connection c = DriverManger.getConnection("jdbc:......", properties);

My question is how do I use

DriverManger.setLoginTimeout(10);

to set the connection time out. If after 10 seconds still not
able to connect to the database, then time out. throw to
Exception
By default if there is something wrong with the database server
or the host. It may takes 30 seconds to catch in Exception.
I want to shorter it to only 10 seconds. How do I do that?

Thank Q very much in advance!
 
S

Sudsy

RC said:
The Subject says its all.

I can't do

DriverManager dm = new DriverManager();

But I can do

Connection c = DriverManger.getConnection("jdbc:......", properties);

My question is how do I use

DriverManger.setLoginTimeout(10);

to set the connection time out. If after 10 seconds still not
able to connect to the database, then time out. throw to
Exception
By default if there is something wrong with the database server
or the host. It may takes 30 seconds to catch in Exception.
I want to shorter it to only 10 seconds. How do I do that?

Thank Q very much in advance!

DriverManger.setLoginTimeout(10);
Connection c = DriverManger.getConnection("jdbc:......", properties);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top