I have a java class where i have a method which is returning me a json i want to call that method into my servlet doGet method so that i can make a AJAX call later
but while calling the java class method (Outlet.Outlet) it asks for a parameter to pass i dont know what to pass there please have a look into my code
this is my java class
public class Outlet {
static Connection con = null;
static Statement statement = null;
ResultSet resultSet = null;
public static String Outlet(String idDB) throws ClassNotFoundException, SQLException {
List<String> list = new ArrayList<String>();
con = DBConnection.createConnection();
statement = con.createStatement();
String sql="select CUSTOMERDESCRIPTOR as OUTLETNAME from ecustomer where CUSTOMERIDENTIFIER in(select CUSTOMERIDENTIFIER from mt_distributrol where mt_distributr_vcdistributrcode = '"+idDB+"')";
System.out.println("iddb :"+idDB);
try {
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
list.add(resultSet.getString("OUTLETNAME"));
}
} catch (SQLException e) {
e.printStackTrace();
}
String json = new Gson().toJson(list);
System.out.println("Json Outlet :"+json);
return json;
}
}
In the above java class i am returning a Json and i want to call that method into my servlet doGost
my doGet is
try {
String json = Outlet.Outlet(); //what should i pass here as a parameter
response.setContentType("application/json");
response.getWriter().write(json);
System.out.println("dheeraj"+json);
}
catch (Exception e) {
e.printStackTrace();
}
}
if i am passing idDB then it throws error.please anybody having any knowledge help me out