I am running sample.jar file in Windows Server 2003, which are connecting to a MySQL in a linux OS server using JDBC. I notice that there is a limit for JDBC connections within certain time. For example, I run the sample.jar file and after it looped for 20 times (every loop there is a connection established, but is closed at the end of the loop), then it start to show the error log as below:
SQLException: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communica tions link failure Last packet sent to the server was 0 ms ago.
I tried to terminate the process, and re-execute the sample.jar file, it shows the same error log. But if I re-execute the sample.jar file after few minutes, it runs fine again, but encounter same error after 20 loops.
I then run the same sample.jar file in Windows 7 professional, it won't encounter this error even though it looped for 200++ times.
Thus, I am wondering if there is any configurations to configure the maximum JDBC connection within certain period for Windows Server 2003? If it does, how is it been configured?
Additional info: This is the function of establising the connection to MySQL service:
public static Connection getConnection()throws NamingException,SQLException {
Connection con = null;
try {
String url = "jdbc:mysql://192.168.100.11:3306/mydatabase";
con = DriverManager.getConnection (url, "root", "password");
} catch (SQLException e) {
System.out.println("SQLException: "+e);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Exception: "+e);
}
return con;
}
It catches the exceptions at SQLExeption.