3.2.0

trouble retrieve data to grid

hi,

I use the grid on my application, but why the data & the grid couldn't
be created on the page??

this is my code :

<%@ include file="/taglibs.jsp"%>
<%@ taglib prefix='c' uri='http://java.sun.com/jstl/core_rt' %>
<%@ page  language="java" import="java.sql.*"%>

<html>
<head>
<title>Tes Grid</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="control/runtime/styles/xp/grid.css" rel="stylesheet" type="text/css" >
<script src="control/runtime/lib/grid.js"></script>
<script src="control/patches/paging1.js"></script>
<style type="text/css">
        .active-column-0 {width:40pt; text-align:center; background-color:#FFFFCC;}
        .active-column-1 {width: 110pt; background-color:#CCFFFF;}
        .active-column-2 {width: 60pt; text-align:center; background-color:#FFFFCC;}        
        .active-column-3 {width: 100pt; text-align:center; background-color:#CCFFFF;}
        .active-column-4 {width: 100pt;}        
        .active-column-5 {width: 100pt; text-align:center; background-color:#CCFFFF;}
        .active-grid-column {border-right: 1px solid black;}
        .active-grid-row {border-bottom: 1px solid black;}
        .active-templates-header{font-weight:bold; color:green; text-align:center;}        

</style>
</head>
<%

    try{
        Class.forName("oracle.jdbc.OracleDriver");//connect driver
    }
    catch(ClassNotFoundException ce){
        out.print(ce.getMessage());
    }
%>
<body>
<%

    boolean flag = false;
    String datagrid = "var myData=[\n";
                String sConnect = "jdbc:oracle:thin:@//rtgsdbsvr:1521/praweda";//I am using MySQL database
                String sUserName = "rt2"; //you define ex: "root"
                String sPassword="rt2";//you define ex: "1234567".. ect 
    try{
        Connection connect = DriverManager.getConnection(sConnect, sUserName, sPassword);
        ResultSet rs = null;
        Statement st = connect.createStatement();
        rs = st.executeQuery("SELECT * FROM RT2.T_AID");
        
        while(rs.next()){
%>
        <!-- this "table test" is work properly to retrieve data -->
               <table>
            <tr>
                <td><%= rs.getString("AID") %></td>
            </tr>
        </table>

    <%

        datagrid += "[\""+rs.getString("AID")+"\"]\n";
    
    %>
<%


            if(!flag){
                flag = true;
                datagrid += "[\""+rs.getInt(1)+"\",\""+rs.getString(2)+"\",\""+rs.getString(3)+"\",\""+rs.getString(4)+"\"]\n";
            }
            else{
                datagrid += ",[\""+rs.getInt(1)+"\",\""+rs.getString(2)+"\",\""+rs.getString(3)+"\",\""+rs.getString(4)+"\"]\n";
            }
        }
        datagrid += "];\n";
        rs.close();
        st.close();
        connect.close();
    }
    catch(SQLException se){
        out.print(se.getMessage());
    }
%>
<script>
var myTitle=["Column 1", "Column 2", "Column 3", "Column 4"];
<%=datagrid %>

var obj = new Active.Controls.Grid;
var row = new Active.Templates.Row; //add double click event
row.setEvent("ondblclick", function(){this.action("myAction")}); 
obj.setTemplate("row", row); 
obj.setModel("row", new Active.Rows.Page);
obj.setColumnHeaderHeight(25);    
obj.setProperty("row/count", myData.length-1);//(myData.length-1) is total rows
obj.setProperty("column/count", 6);
obj.setProperty("data/text", function(i, j){return myData[i][j]});
obj.setProperty("column/texts", myTitle);
obj.setProperty("row/pageSize", 25);

document.write(obj);
</script>
</body>
</html>
Mr.K
November 26,

This topic is archived.

See also:


Back to support forum