Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I Had Written A Jsp Page With Database Connectivity Getting The Data From The Database And Printing It Json Format. And I Want That Json Data To Be Sent To The Dojo Data Grid
XML
[{"sl":"1","id":"1","name":"shivasrinat"}

urgent any one pls help me.

1.i had written a jsp page with database connectivity getting the data from the database and printing it json format.

And now i want that json data to be sent to the dojo data grid

Any help?

2.here is my jsp code.

<html>
<head>
    <script type="text/javascript">
        dojo.require("dojox.data.QueryReadStore");
        dojo.require("dojox.grid._CheckBoxSelector");
        dojo.require("dojo.data.ObjectStore");
        dojo.require("dojo.parser");
        dojo.require("dojox.grid.DataGrid");
        dojo.require("dijit/form/Button");
        dojo.require("dojox/grid/DataGrid");
        dojo.require("dojo/data/ItemFileReadStore");
        dojo.ready(function(){
            mystore=new dojox.data.QueryReadStore({url:"/DojoProject/test"});
            grid = new dojox.grid.DataGrid({
                    store: mystore,
                    structure: [
                        {type: "dojox.grid._CheckBoxSelector",  editable: true},
                       [{name:"id", field:"ID", width: "200px",editable: true},
                        {name:"name", field:"name", width: "200px",editable: true},
                        {name:"Result", field:"Result", width: "200px"}]
                    ]}, dojo.byId("gridContainer"));
           grid.startup();
        });
    </script>
<%
    JSONObject responseObj = new JSONObject();
    List<JSONObject> data = new LinkedList<JSONObject>();
    try {
        String dbms = "SQL SERVER";
        String serverName = "";
        String portNumber = "1106";
        String userName = "";
        String upassword = "";
        String databaseName = "";
        int datacount = 0;

        //String connectionURL = "jdbc:" + dbms + "://" + sN
        //      + ":" + PN + "/" + databaseN;
        Connection conn = null;
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        conn = DriverManager.getConnection("");
        System.out.println("connection::" + conn);

        String strQuery = "select * from sample";
        System.out.println(strQuery);
        PreparedStatement st = conn.prepareStatement(strQuery);
        ResultSet rs = st.executeQuery();
        while(rs.next()) {
            datacount++;
            JSONObject object = new JSONObject();
            object.put("s1",(String.valueOf(datacount)));
            object.put("ID",rs.getString(1));
            object.put("Name",rs.getString(2));
            System.out.println("ID&name&::"+rs.getString(1) +","+rs.getString(2));
        }
        responseObj.put("data",data);
        PrintWriter writer = response.getWriter();                           System.out.println({\"identifier\":\"data\",\"label\":\"data\",\"items\":"+responseObj+"}");
        writer.write(" "+responseObj+"");
        writer.flush();
        writer.close();
    } catch (Exception e) {
        System.out.println(e);
    }  %>
urgent help me any one.
Posted
Updated 12-Aug-14 22:47pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900