0

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.

PaulLing
  • 2,068
  • 3
  • 17
  • 21
  • Not JDBC. How many CALs do you have? – Elliott Frisch Jun 21 '17 at 15:21
  • I have no idea what CALs means, perhaps I can get some reference? – PaulLing Jun 21 '17 at 15:31
  • This is about how your MySQL server is configured. It has nothing to do with JDBC. – user207421 Jun 21 '17 at 17:38
  • I'd first try to make sure your code is actually closing the connections correctly. Consider adding your code to this question, and please: also post the full exception stacktrace, it provides more information than just the message of the top exception. Also IIRC Windows Server 2003 by default has a relatively low limit of half-open connections, although that should only affect opening connections. – Mark Rotteveel Jun 21 '17 at 18:58
  • Hi Mark, I edited my post, includes the code which returns the error message. The message that I post is the entire message that it returns. – PaulLing Jun 21 '17 at 23:02
  • The stacktrace contains the stack of methods calls and an exception cause; that cause might provide more clues what the underlying problem is; the error message alone is not enough information. I suggest you either remove the separate catch for `SQLException`, or add an `e.printStackTrace()` to that catch as well. – Mark Rotteveel Jun 22 '17 at 14:18

0 Answers0