473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Combine methods

I have a 2 methods working in my class file that I am trying to convert into 1 method:

Expand|Select|Wrap|Line Numbers
  1. .....
  2. public Preparestatement prep;
  3. public int inserterOne(TheBean mybean)
  4. {
  5.     int status = 0;
  6.     try {
  7.     prep.connection.preparestatement("insert into person (city, state) values (?,?)");
  8.     prep.setString(1,mybean.getCity());
  9.     prep.setString(2,mybean.getState());
  10.     prep.executeUpdate();
  11.     }
  12.     catch(Exception e) {
  13.          e.printStacktrace();
  14.     }
  15.     return status;
  16.  }
  17.  
  18. public int inserterTwo(TheBean mybean)
  19. {
  20.     int status = 0;
  21.     try {
  22.     prep.connection.preparestatement("insert into person (city, state) values (?,?)");
  23.     prep.setString(1,mybean.getMainCity());
  24.     prep.setString(2,mybean.getMainState());
  25.     prep.executeUpdate();
  26.     }
  27.     catch(Exception e) {
  28.          e.printStacktrace();
  29.     }
  30.     return status;
  31.  }
  32.  
  33. public int hitter(TheBean mybean)
  34. {
  35. .....
  36. inserterOne(mybean);
  37. inserterTwo(mybean);    
  38. ...


Here is my attempt and not sure how to make this work?
Expand|Select|Wrap|Line Numbers
  1. public int inserterCombined(TheBean mybean, ??)
  2. {
  3.     int status = 0;
  4.     try {
  5.     prep.connection.preparestatement("insert into person (city, state) values (?,?)");
  6.     prep.setString(1,mybean.getCity());
  7.     prep.setString(2,mybean.getState());
  8.     prep.executeUpdate();
  9.  
  10.     prep.setString(1,mybean.getMainCity());
  11.     prep.setString(2,mybean.getMainState());
  12.     prep.executeUpdate();
  13.     }
  14.     catch(Exception e) {
  15.          e.printStacktrace();
  16.     }
  17.     return status;
  18.  }
  19.  
  20. ....
  21. public int hitter(TheBean mybean)
  22. {
  23. .....
  24. inserterCombined(?? here);  
Please advise.
Oct 8 '07 #1
2 3532
r035198x
13,262 8TB
Why would you want to "combine" methods?
Do they do the same thing or do you want to call one method after the other?
What happened on your attempt? Did you get errors/exceptions?
Oct 8 '07 #2
JosAH
11,448 Expert 8TB
I have a 2 methods working in my class file that I am trying to convert into 1 method:
Don't; go the other way instead and split them up even further (folks call that
'refactoring'). Suppose you have two methods:

M1: a B c
M2: a' B c'

where B is the common part of them both and a, a', c and c' are the unique
prefixes and postfixes of both methods. Design a third method M3 such that
you can rewrite your methods M1 and M2 like this:

M1: a M3 c
M2: a' M3 c'
M3: B

More methods are nothing to be ashamed of, the opposite is.

kind regards,

Jos
Oct 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Patrick | last post by:
Is it possible to combine two dll assemblies into one? If so, how? TIA Patrick
3
by: Nick | last post by:
I am working a new application...well actually a series of applications for my company. They want internal users to be able to go to a site and everything regarding security is transparent,...
2
by: TJO | last post by:
What is the best way to combine two byte? I am not finding one yet. Thanks
1
by: William Stacey [MVP] | last post by:
I need a bullet proof way to combine a root and a relative path to form a FQ rooted path (similar to a VDir in IIS). Path.Combine alone will not do the job in all cases. I also need to be sure...
3
by: steve_h | last post by:
I think the subject says it all, but just in case: I know that I can call my own methods during an XSL transformation using <xsl:value-of select="myObject.someMethod(arg1)" /> having done...
3
by: Schroeder, AJ | last post by:
Hello group, I am a relative PHP newbie and I am trying to combine two arrays together, but I also need to keep the keys of one array intact. What I am doing is two SNMP walks against a Cisco...
2
by: nugz | last post by:
I want to combine 3 tables with like data then append it with a filter. Tables: NewStarts, Complaints, Memos Combine: Date, Address, Route, Pub, etc.... Then sort: previous 8 days, pub/freq...
0
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I have some methods which generate html formatting for text on the fly. I generally use <spantags and that works fine. But, I would like to be able to combine different formatting elements on...
1
by: LSGKelly | last post by:
Hi all. I need to combine two fields that contain numbers that are in a currency format (Ex: $1,500 $3,500). When I combine them, I want them to look like this -- $1,500/$3,500. When I combine...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.