11

I've read all "System resource exceeded" posts, but this is nothing like them. I've spend the last 3 hours searching for a solution. I don't have many connections / statements / resultsets and I always close all of them. My code used to work but now I get the "System resource exceeded" exception, not during queries, but WHEN I TRY TO CONNECT. I didn't change a thing from my code, however it doesn't work at the moment, except 1 out of 10 times I try it. I tried to change some things in it but no difference. My Access files are 15 - 50 MB. My code is:

private String accessFilePath;
private Connection myConnection;
public boolean connectToAccess(String myAccessFilePath) {
    accessFilePath = myAccessFilePath;
    //Get connection to database
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        // set properties for unicode
        Properties myProperties = new Properties();
        myProperties.put("charSet", "windows-1253");
        myConnection = DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=" + accessFilePath, myProperties); // I get the exception here
    } catch (Exception ex) {
        System.out.println("Failed to connect to " + accessFilePath + " database\n" + ex.getMessage());
        return false;
    }
    return true;
}

What is now different from other times? Do Access files keep previous connections open? What can be wrong here?

Stefanos Kargas
  • 10,547
  • 22
  • 76
  • 101
  • 1
    Have you tried restarting your Operating System ? It could be that some connection-related resources were never deallocated due to, perhaps, interrupted runs of your program which never managed to close their connection. – Mike Nakis Jan 11 '12 at 19:27
  • I've tried restart already. It was my first thought. I find it very strange that after a fresh restart, I get the exception during the first connection try. It's crazy... I also get the same exception for various Access files – Stefanos Kargas Jan 11 '12 at 19:36
  • 1
    Wow, that's bizarre. Next thing to try: can you access these files from C# or VB using ADO? – Mike Nakis Jan 11 '12 at 19:42

1 Answers1

6

OK, I found the solution. At first I started a new java project and copied the same codelines there. I successfully connected to my files every time I tried it in my new project. So it struck me. I looked at my VM settings. In my original program I ASSIGNED TOO MUCH MEMORY TO THE VIRTUAL MACHINE so there was no memory left even for a single connection to the files.

My settings were --> VM Options: -Xmx1536m -Xms768m (a little bit excessive)

I changed it to --> VM Options: -Xmx512m -Xms256m

And it worked. Thank you for your comments. I hope this helps other people, because I spend many hours to find it.

Stefanos Kargas
  • 10,547
  • 22
  • 76
  • 101