Mike :
I am coming to a problem where I want to call a method from one class to another, but this method has a parameters. I tried doing String searchData = "searchValue"
from my another class, but it for my other class is not being called.
Here is my code:
The method that I want to call
public List<JobSearchItem> getJobAutocomplete(String searchValue) {
String sValue = "%" + searchValue.toUpperCase() + "%";
return dataUtilityService.getJdbcTemplate().query(SQL_GET_JOB_SEARCH_LISTS,
new Object[]{sValue, sValue}, jobSearchItemMapper);
}
the other method that I want to call the above code
public void loadSearchList() throws SQLException, NamingException, URISyntaxException, IOException, ParseException {
String searchData = "searchValue";
List<JobSearchItem> jobSearchList = XPayService.getJobAutocomplete(searchData);
this.setJobSearchItems(jobSearchList);
}
AK47 :
You either need an instance of the XPayService
class to call the method on, or else you can make the method static
Using an instance of the class:
class XPayService() {
public List<JobSearchItem> getJobAutocomplete(String searchValue) {
String sValue = "%" + searchValue.toUpperCase() + "%";
return dataUtilityService.getJdbcTemplate().query(SQL_GET_JOB_SEARCH_LISTS,
new Object[]{sValue, sValue}, jobSearchItemMapper);
}
}
public void loadSearchList() throws SQLException, NamingException, URISyntaxException, IOException, ParseException {
XPayService xps = new XPayService();
String searchData = "searchValue";
List<JobSearchItem> jobSearchList = xps.getJobAutocomplete(searchData);
this.setJobSearchItems(jobSearchList);
}
Using a static method:
class XPayService() {
public static List<JobSearchItem> getJobAutocomplete(String searchValue) {
String sValue = "%" + searchValue.toUpperCase() + "%";
return dataUtilityService.getJdbcTemplate().query(SQL_GET_JOB_SEARCH_LISTS,
new Object[]{sValue, sValue}, jobSearchItemMapper);
}
}
public void loadSearchList() throws SQLException, NamingException, URISyntaxException, IOException, ParseException {
String searchData = "searchValue";
List<JobSearchItem> jobSearchList = XPayService.getJobAutocomplete(searchData);
this.setJobSearchItems(jobSearchList);
}