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

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top