Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="select * from ordertable"; ResultSet rs=stmt.executeQuery(sql); int i=1; String result=null; String rowcount=null; JSONObject jsonObject = new JSONObject(); while(rs.next()) {
//Map<String,Object> tree = new HashMap<String,Object>(); //tree.put("id",i); //tree.put("dorder", rs.getString(1)); //tree.put("xdate", rs.getString(2));
toJson 这个方法在那个类里面?(包org.json),谢谢!
你可以查看下json.jar。以及搜下对应的api
JSONObject.fromObject(Object);
哈哈 全写了烦 你上网看看 很多的例子
<%
//Class.forName("com.mysql.jdbc.Driver").newInstance();
Class.forName("com.mysql.jdbc.Driver");
//tring url ="jdbc:mysql://localhost:3306/book?username=root&password=123456";
//testDB为你的数据库名
//Connection conn= DriverManager.getConnection(url);
String url = "jdbc:mysql://127.0.0.1/testorder?useUnicode=true&characterEncoding=utf-8";
String user = "root";
String psw = "123456";
Connection conn = DriverManager.getConnection(url,user,psw);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from ordertable";
ResultSet rs=stmt.executeQuery(sql);
int i=1;
String result=null;
String rowcount=null;
JSONObject jsonObject = new JSONObject();
while(rs.next()) {
//Map<String,Object> tree = new HashMap<String,Object>();
//tree.put("id",i);
//tree.put("dorder", rs.getString(1));
//tree.put("xdate", rs.getString(2));
jsonObject.put("id", (Object)rs.getString(1));
jsonObject.put("dorder", (Object)rs.getString(2));
jsonObject.put("xdate", (Object)rs.getString(3));
if (i==1)
{
result = jsonObject.toString();
}
else
{
result += "," + jsonObject.toString();
}
i++;
}
//System.out.println(jsonObject.toString());
rs.close();
stmt.close();
conn.close();
rowcount=String.valueOf(i-1);
response.getWriter().write("{total:"+rowcount+",stocks:[" + result + "]}");
%>
GetorderData.jspvar typeStore = new Ext.data.Store({//配置分组数据集
//autoLoad :true,
reader: new Ext.data.XmlReader({
totalRecords: "total",
record: "stocks",
id: "id"
},
Ext.data.Record.create([
{name: 'id'},
{name: 'dorder'},
{name: 'xdate'}
])
),
proxy : new Ext.data.HttpProxy({
url : 'pagesExt/GetOrderData.jsp'
})
})
var cb = new Ext.grid.CheckboxSelectionModel()
var bookTypeGrid = new Ext.grid.GridPanel({
applyTo : 'grid-div',
tbar : toolbar,
frame:true,
store: typeStore,
viewConfig : {
autoFill : true
},
sm : cb,
columns: [//配置表格列
new Ext.grid.RowNumberer({
header : '行号',
width : 40
}),//表格行号组件
cb,
{header: "编号", width: 80, dataIndex: 'id', sortable: true,hidden:true},
{header: "单号", width: 180, dataIndex: 'dorder', sortable: true},
{header: "下单日期", width: 280, dataIndex: 'xdate', sortable: true}
],
bbar: new Ext.PagingToolbar({
pageSize: 10,
store: typeStore,
displayInfo: true,
displayMsg: '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
emptyMsg: "没有记录"
}),
renderTo:'grid'
});
typeStore.load({params:{start:0, limit:10}});
怎么grid里面显示不了数据啊?