问题一堆的一天
发布时间:2020-12-16 19:05:13 所属栏目:百科 来源:网络整理
导读:今天碰到的问题奇奇怪怪的。。。慢慢来吧 JSONArray的用法: public String select (){ try { // 连接数据库 /** * 将查询的信息已json的方式返回 * 并在json中添加jsonarray */ Connection conn = SQLManager.newInstance().getConnection(); PreparedState
今天碰到的问题奇奇怪怪的。。。慢慢来吧 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;
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |