Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: jdbc connections

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question jdbc connections

    I had existing function (f1) that opens and does select sql and returns results and closes connection.

    Now I need to call the f1 many time. so in a loop

    loop begins
    f1
    loop ends.

    As long as the f1 opens and closes the jdbc connection I should not have any problem whatever the number of times it loops.

    But I do see problem max connections sql exception

    java.sql.SQLException: Network error IOException: No buffer space available (maximum connections reached?): connect
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(C onnectionJDBC2.java:385)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(C onnectionJDBC3.java:50)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.ja va:182)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.cleverdevices.bustime.util.DatabaseUtil.openDa tabaseConnection(DatabaseUtil.java:68)
    at com.cleverdevices.bustime.scheduleevaluator.Schedu leEvaluator.getHistoricalScheduleAdherenceResults( ScheduleEvaluator.java:877)
    at com.cleverdevices.bustime.scheduleevaluator.Schedu leEvaluatorIFImpl.getHistoricalScheduleAdherenceRe sults(ScheduleEvaluatorIFImpl.java:450)
    at sun.reflect.GeneratedMethodAccessor3.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    at sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages( Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run0(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.net.SocketException: No buffer space available (maximum connections reached?): connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.sourceforge.jtds.jdbc.SharedSocket.createSocke tForJDBC3(SharedSocket.java:304)
    at net.sourceforge.jtds.jdbc.SharedSocket.<init>(Shar edSocket.java:255)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(C onnectionJDBC2.java:310)
    ... 20 more


    obviously if I connection before loop and close after loop it is ok. But my theory as long as we close everytime it should work ..

    what is missing. "netstat" lists the db connections ports..

    ofcourse when I stop the tomcat server..it clears.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: jdbc connections

    Provide an SSCCE (or as close as you can get) detailing what is causing the exception - we cannot comment on code that we do not know about

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: jdbc connections

    my question in not regarding my code.

    My questions is if we loop open/close connection lets say 20k to 30k times, will that be a problem? I thought as long as we open and close, it should not be a problem. or is there a limitation?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: jdbc connections

    Quote Originally Posted by rlk View Post
    my question in not regarding my code.

    My questions is if we loop open/close connection lets say 20k to 30k times, will that be a problem? I thought as long as we open and close, it should not be a problem. or is there a limitation?
    Honestly I never tried it - theoretically it should work, but in my opinion is very bad practice.

  5. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: jdbc connections

    thanks. In my try, it did not work and i got max connections reached exception. I moved the open/close outside the loop. I also thought theoratically it should work. but looks like the loop goes faster that the open/close.

Similar Threads

  1. JDBC Problem - com.mysql.jdbc.Driver
    By icu222much in forum Java Servlet
    Replies: 2
    Last Post: November 21st, 2011, 11:54 PM
  2. Replies: 0
    Last Post: January 12th, 2011, 08:41 AM
  3. Socket connections and Unsigned values
    By helloworld922 in forum Java Networking
    Replies: 5
    Last Post: June 15th, 2010, 08:48 PM
  4. How can i create fake IP addresses to extract information for the DB?
    By neomancer in forum Java Theory & Questions
    Replies: 4
    Last Post: May 8th, 2009, 04:54 AM
  5. How to Create a server socket to listen for incoming connections?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: May 5th, 2009, 08:02 AM