今天碰到的问题奇奇怪怪的。。。慢慢来吧
JSONArray的用法:
- public String select(){
- try {
- // 连接数据库
- /** * 将查询的信息已json的方式返回 * 并在json中添加jsonarray */
- Connection conn = sqlManager.newInstance().getConnection();
- PreparedStatement statement = conn
- .prepareStatement("select * from user");
- ResultSet set = statement.executeQuery();
- JSONObject obj = new JSONObject();
- JSONArray array=new JSONArray();
- set.first();
- while(!set.isAfterLast()) {
- JSONObject item = new JSONObject();
- item.put("username",set.getString("user_name"));
- item.put("password",set.getString("password"));
- array.add(item);
- set.next();
- }
- obj.put("code",0);
- obj.put("message","查询成功");
- obj.put("data",array);
- return obj.toString();
- } catch (sqlException e) {
- e.printStackTrace();
- }
- return null;
- }