这段代码: while (rs.next()){
JSONArray jsonArray=new JSONArray();
JSONObject jsonObject=new JSONObject();
jsonObject.put("C01",rs.getString(1));
jsonObject.put("C02",rs.getString(2));
jsonObject.put("C03",rs.getString(3));
jsonObject.put("C04",rs.getString(4));
jsonObject.put("C05",rs.getString(5));
jsonObject.put("C06",rs.getString(6));
jsonObject.put("C07",rs.getString(7));
jsonObject.put("C08",rs.getString(8));
jsonObject.put("C09",rs.getString(9));
jsonArray.add(jsonObject)
PrintWriter pw=resp.getWriter()
pw.write(jsonArray.toString())
pw.flush();
pw.close();
return;
}
第一:我的数据库里有100条记录,怎么前端打印出来只有数据库里第一条记录?请问怎么修改代码
第二:我想把记录集rs,转成这种格式的json {“data”:[["1","2","3","4","5","6","7","8","9"],["1","2","3","4","5","6","7","8","9"],["1","2","3","4","5","6","7","8","9"]]}
JSONArray jsonArray=new JSONArray();
JSONObject jsonObject=new JSONObject();
jsonObject.put("C01",rs.getString(1));
jsonObject.put("C02",rs.getString(2));
jsonObject.put("C03",rs.getString(3));
jsonObject.put("C04",rs.getString(4));
jsonObject.put("C05",rs.getString(5));
jsonObject.put("C06",rs.getString(6));
jsonObject.put("C07",rs.getString(7));
jsonObject.put("C08",rs.getString(8));
jsonObject.put("C09",rs.getString(9));
jsonArray.add(jsonObject)
PrintWriter pw=resp.getWriter()
pw.write(jsonArray.toString())
pw.flush();
pw.close();
return;
}
第一:我的数据库里有100条记录,怎么前端打印出来只有数据库里第一条记录?请问怎么修改代码
第二:我想把记录集rs,转成这种格式的json {“data”:[["1","2","3","4","5","6","7","8","9"],["1","2","3","4","5","6","7","8","9"],["1","2","3","4","5","6","7","8","9"]]}