I have a java class ::
package MyPackage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import com.google.gson.Gson;
public class PopulateTextbox {
Gson gson = new Gson();
JSONObject obj = new JSONObject();
JSONArray arr = new JSONArray();
String temp1;
String temp;
List <String>rowValues = new ArrayList<String>();
List <Integer>rowValues1 = new ArrayList<Integer>();
String[] contactListNames;
Connection con=null;
Statement st=null;
ResultSet rs=null;
public String method(){
try{
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
String db = "jdbc:odbc:Practice_Database";
con = DriverManager.getConnection(db,"","");
st = con.createStatement();
String sql = "SELECT Emp_Name,ID,Email_Add FROM EmployeeSearch";
rs = st.executeQuery(sql);
while(rs.next()){
obj.put("ID", rs.getInt("ID"));
obj.put("Names",rs.getString("Emp_Name"));
obj.put("Email", rs.getString("Email_Add"));
arr.add(obj);
}
temp1 = arr.toString();
System.out.println(temp1);
}catch(Exception e){System.out.println(e);}
return temp1;
}
public static void main(String args[])
{
PopulateTextbox obj = new PopulateTextbox();
String temp1= obj.method();
}
}
This returns me a Json array. Now I want to call the method () of this class in JavaScript again and again to get new values when updating my database. I have a data grid that works fine since the page loads for the first time with a set of values in this json array. But how to update data using Ajax. Or how to call the () method using Ajax so that the data is updated when I click the button on the page. The code in which I call this method in java-script is ::
<%
String temp1;
PopulateTextbox obj = new PopulateTextbox();
temp1 = obj.method();
%>
I get a problem when getting a new set of values in temp1 via an Ajax call to the server. please help? Thank you
source
share