Calling Method of another class from Recursion Method: Java

deen

I have two class as A and B-

Class A:- This class has getData method, which is used to get data from DB.

class A {
    public synchronized getData() {
       // get some data from database, in finally block close connection
    }
}

Class B:- Which has recursion method m(), inside this method I am calling the getData() of class A.

class B {
   m() {
      //some condition to terminate the recursion
      A a = new A();
      a.getData();
      m();
   }
}

Error I am getting:-

java.lang.NullPointerException: null at com.mchange.v2.c3p0.impl.NewProxyConnection.getAutoCommit(NewProxyConnection.java:1226) ~[c3p0-0.9.5.1.jar:0.9.5.1]

For the first call of getData() method, I am able to get data from DB, but after second recursion onward I am getting the connection as closed. Any help would be highly appreciated.

Update:

I have DB Util method which is opening the connection each time when getData() method is calling. It's working fine if I am calling this without recursion method(many times) but if I am using recursion I'm getting error. Is any special case I have to handle for recursion method?

cse

The error specifies that connection is closed. Also, in your comment // get some data from database, in finally block close connection, you have mentioned that you have closed the connection after use but, you didn't mentioned that if you are opening the connection in he getData() method or not.

I would suggest following:

  • Check if you are opening the connection in getData() method. If not then either open the connection in this method only(remove the code for opening connection from some other method) or don't close the connection after use in this method instead use a different method to close the connection as per need.
  • Check if connection resource is reusable.
  • Collected from the Internet

    Please contact [email protected] to delete if infringement.

    edited at
    0

    Comments

    0 comments
    Login to comment

    Related

    From Java

    java calling a method from another class

    From Java

    Calling method of Another class from run() method

    From Javascript

    Calling a method from another method in the same class

    From Java

    calling another method from the main method in java

    From Dev

    Calling a class from another class with main method

    From Dev

    Calling a method from one class in another class

    From Java

    Java cannot find symbol when calling a method from another class

    From Java

    Having trouble calling a method to edit a string from another class in java

    From Dev

    calling MainActivty's method from another java class without onCreate

    From Dev

    Java LIBGDX, Calling InputHandler's TouchDown method from another class

    From Dev

    Java - Calling Boolean Method from another class with arraylist parameter

    From Dev

    Calling a method from inside of another class

    From Dev

    Calling a method of the MainActivity from another class?

    From Dev

    Calling method from another class unsuccessful

    From Java

    Calling service method from another service class

    From Java

    NullPointerException when calling method from another class

    From Dev

    JGroups RpcDispatcher calling method from another class

    From Dev

    calling render method from another class

    From Dev

    calling method in mainactivity from another class in android

    From Dev

    Python: Calling a decorator method from another class

    From Dev

    Having trouble calling a method from another class

    From Dev

    Syntax Error in Calling a method from another class

    From Dev

    calling a boolean method from another class

    From Dev

    Calling a method from another class in broadcast receiver

    From Dev

    Calling a method from another class that removes views

    From Dev

    Calling StartActivity(intent) method from another class

    From Dev

    python, calling a method from another class

    From Dev

    Calling a class method from another class method in Python 2.7

    From Java

    Calling a method from another method

    Related Related

    1. 1

      java calling a method from another class

    2. 2

      Calling method of Another class from run() method

    3. 3

      Calling a method from another method in the same class

    4. 4

      calling another method from the main method in java

    5. 5

      Calling a class from another class with main method

    6. 6

      Calling a method from one class in another class

    7. 7

      Java cannot find symbol when calling a method from another class

    8. 8

      Having trouble calling a method to edit a string from another class in java

    9. 9

      calling MainActivty's method from another java class without onCreate

    10. 10

      Java LIBGDX, Calling InputHandler's TouchDown method from another class

    11. 11

      Java - Calling Boolean Method from another class with arraylist parameter

    12. 12

      Calling a method from inside of another class

    13. 13

      Calling a method of the MainActivity from another class?

    14. 14

      Calling method from another class unsuccessful

    15. 15

      Calling service method from another service class

    16. 16

      NullPointerException when calling method from another class

    17. 17

      JGroups RpcDispatcher calling method from another class

    18. 18

      calling render method from another class

    19. 19

      calling method in mainactivity from another class in android

    20. 20

      Python: Calling a decorator method from another class

    21. 21

      Having trouble calling a method from another class

    22. 22

      Syntax Error in Calling a method from another class

    23. 23

      calling a boolean method from another class

    24. 24

      Calling a method from another class in broadcast receiver

    25. 25

      Calling a method from another class that removes views

    26. 26

      Calling StartActivity(intent) method from another class

    27. 27

      python, calling a method from another class

    28. 28

      Calling a class method from another class method in Python 2.7

    29. 29

      Calling a method from another method

    HotTag

    Archive