jdbc mysql loginTimeout nie działa
Czy ktoś może wyjaśnić, dlaczego po 3 sekundach nastąpiło przekroczenie limitu czasu programu, w którym ustawiłem to po 12 sekundach. Celowo wyłączyłem serwer mysql, aby przetestować ten scenariusz, w którym serwer mysql jest nieosiągalny.
import java.sql.Connection;
import java.sql.DriverManager;
/**
*
* @author dhd
*/
public class TestMysql {
static Thread trd;
public static void main(String[] argv) {
keepTrack();
try {
DriverManager.setLoginTimeout(12);
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/driving", "root", "");
} catch (Exception ex) {
System.err.println(ex.getMessage());
trd.stop();
}
}
public static void keepTrack() {
trd = new Thread(new Runnable() {
@Override
public void run() {
int i = 1;
while (true) {
System.out.println(i);
try {
Thread.sleep(1000);
} catch (Exception ex) {
}
i++;
}
}
});
trd.start();
}
}
Dane wyjściowe to:
run: 1 2 3 Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. BUILD SUCCESSFUL (total time: 3 seconds).
Biegnij od netbeans. Zanim zapytasz, dlaczego tego potrzebuję, odpowiedz najpierw. Dzięki