• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing Parameter between Methods

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some problems because i don't really know how to pass parameter between methods in a java class.
How can i do that? below is the code that i did.

I want to pass in the parameter from a method called dbTest where this method will run StringTokenizer to capture the input from a text file then it will run storeData method whereby later it will then store into the database.

How can i pass data between this two methods whereby i want to read from text file then take the value to be passed into the database to be stored?

Thanks alot


[ November 08, 2006: Message edited by: Eric Tan ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you seem to already know how to pass arguments to a method, as (for example) here:

File f = new File("c:\\abc.txt");

In that line, you're sending the String "c:\\abc.txt" to the File constructor; the File constructor does whatever it want to with that String. If you saw File's constructor, it would look like

File(String filename) { ...

That means the constructor takes a single String argument. Inside the File constructor, the String is available as the variable "filename".

So you want "storeData" to take some number of arguments. For example, you might like four arguments:

public void storeDate(String fname, String lname, String city, String state) ...

and then you'd pass those four arguments when you call it, and inside storeData, those four variables would be available.

Now the problem here is that you've written storeData so that it calls dbTest, and written dbTest as if it were going to call storeData; I think you just need to clarify in your mind what each routine does.

Does this help?
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand what you mean about the clarification regarding the storeData and dbTest. Sometimes i also confuse myself on the way i wrote the codes. But i know that i have two instance method inside a class file and my main method is to run the dbTest first and then storeData. I might be wrong in this but please do correct if i am wrong. I will look into the info that you told me. Thanks alot..
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order for me to pass in the parameter from dbTest to storeData. in my main method, how can i declare an object to store it? i know that inside the parentheses is the value what you need to return in order for me to use the storeData method to store my data. Can anyone guide me again on this? i might be wrong in my explanation. Sorry about that. Thanks alot
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic