问题一堆的一天

前端之家收集整理的这篇文章主要介绍了问题一堆的一天前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

今天碰到的问题奇奇怪怪的。。。慢慢来吧

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;
    }
原文链接:https://www.f2er.com/json/289671.html

猜你在找的Json相关文章