Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IS THERE ANY WAY TO CALL A NON-STATIC METHOD TO STATIC METHOD

 
arullis michaelraj
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have one method like.


public static connection getConnection()throws SQLException
{
return getConnection(POOL_NAME);
}

It is one file like DBDelegate.java
i have another method in another file ArConnectionPool.java like

public Connection getConnection(String aPoolNameStr) throwsArReportException
{
}



Here How can i call non-static method through static method?

Is there any possible way?

if it is,please tell me.

I am expecting your reply.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

WELCOME TO JAVARANCH!

WAIT, LET ME PRESS THE Caps Lock key... there, that's better.

Note that we have many different forums here. You picked the "Java News" forum, which is for industry-related announcements, not for Java questions. I'll move this thread to the Java in General (Beginner) forum for you, and I'll meet you over there...
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a static method to call a non-static method, the static method needs access to an instance of the class with the non-static method; i.e.,

ArConnectionPool pool = new ArConnectionPool();
pool.getConnection("foo");

Although based on the name of the class, it seems unlikely that you'll want to create an instance of a connection pool each time you access it -- most likely, a single instance will be held in a static variable somewhere.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic