I have written this code which is returning a Json string.It contains a set of values(names). Now i want to display these values on a jsp page using Dojo data grid. I Don't know how to use this returned Json string as a data for Dojo grid. And how to format the table Structure. Also i want when i click on a particular row in a table(which in this case contains only a single column - Employee name as per my query) a new Window opens up(probably a new JSP page). how to do that? Please help me with the code. Thanks.
PopulateTextbox.java
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 com.google.gson.Gson;
public class PopulateTextbox {
Gson gson = new Gson();
String temp;
List <String>rowValues = new ArrayList<String>();
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 FROM EmployeeSearch";
rs = st.executeQuery(sql);
while(rs.next()){
rowValues.add(rs.getString("Emp_Name"));
}
contactListNames = (String[]) rowValues.toArray(new String[rowValues.size()]);
temp = gson.toJson(contactListNames);
}catch(Exception e){System.out.println(e);}
/*finally{
try {
if(con!=null)con.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(rs!=null)rs.close();
} catch (SQLException e) {
e.printStackTrace();
}try {
if(st!=null)st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}*/
return temp;
}
}