PDA

View Full Version : Problem with XMLReader



talha06
19 Jul 2009, 6:15 AM
Hi,

I'm trying to get design my grid with dynamic datas from DATABASE.. I select data and return them within XML to script. But I can't see anything on my grid.. I tested, I've no problem while taking data from DB.. But nothing to see on grid..

Here's my code, can someone help me?

Thanx in advance..
Talha



Ext.onReady(function() {
var RecordDef = Ext.data.Record.create([
{name: 'id', mapping: 'id'},
{name: 'ad', mapping: 'ad'}
]);
var adlar = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'adSorgu.jsp'
}),
reader: new Ext.data.XmlReader({
record: "liste"
}, RecordDef),
autoLoad: true
});
var grid = new Ext.grid.GridPanel({
renderTo: document.body,
frame: true,
width: 300,
height: 300,
title: 'Ogrenci Bilgileri',
columns: [{
header: '<b>ID</b>',
dataIndex: 'id',
width: 25
}, {
header: '<b>Ogrenci Adi</b>',
dataIndex: 'ad',
width: 150
}],
store: adlar

});
});


Server-side:


try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ogrdb","root", "");
Statement st = con.createStatement();
String sql = "select AdSoyad from ogr";
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<?xml version='1.0' encoding='ISO-8859-1'?>");
int id = 0;
ResultSet rs = st.executeQuery(sql);
while(rs.next()) {
id++;
System.out.println("Cekilen Veri: " + rs.getString("AdSoyad")); // for testing
response.getWriter().write("<liste>");
response.getWriter().write("<id>" + id + "</id>");
response.getWriter().write("<ad>" + rs.getString("AdSoyad") + "</ad>");
response.getWriter().write("</liste>");
}
rs.close();
st.close();
con.close();
} catch(Exception e) {
e.printStackTrace();
}

Condor
19 Jul 2009, 10:33 PM
You need another tag that surrounds all <liste> tags.