Convert ResultSet to JSON and XML
public static JSONArray convertToJSON(ResultSet resultSet)
throws Exception {
JSONArray jsonArray = new JSONArray();
while (resultSet.next()) {
int total_rows = resultSet.getMetaData().getColumnCount();
JSONObject obj = new JSONObject();
for (int i = 0; i < total_rows; i++) {
obj.put(resultSet.getMetaData().getColumnLabel(i + 1)
.toLowerCase(), resultSet.getObject(i + 1));
jsonArray.put(obj);
}
}
return jsonArray;
} public static String convertToXML(ResultSet resultSet)
throws Exception {
StringBuilder xmlArray = new StringBuilder("<results>");
while (resultSet.next()) {
int total_rows = resultSet.getMetaData().getColumnCount();
xmlArray.append("<result ");
for (int i = 0; i < total_rows; i++) {
xmlArray.append(" ").append(resultSet.getMetaData().getColumnLabel(i + 1)
.toLowerCase()).append("='").append(resultSet.getObject(i + 1)).append("'");
}
xmlArray.append(" />");
}
xmlArray.append("</results>");
return xmlArray.toString();
}
Convert ResultSet to JSON and XML的更多相关文章
- staxon实现json和xml互转
pom.xml: <dependency> <groupId>de.odysseus.staxon</groupId> <artifactId>stax ...
- 【ASP.NET Web API教程】6.2 ASP.NET Web API中的JSON和XML序列化
谨以此文感谢关注此系列文章的园友!前段时间本以为此系列文章已没多少人关注,而不打算继续下去了.因为文章贴出来之后,看的人似乎不多,也很少有人对这些文章发表评论,而且几乎无人给予“推荐”.但前几天有人询 ...
- Asp.Net Web API 2第十三课——ASP.NET Web API中的JSON和XML序列化
前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs.com/aehyok/p/3446289.html 本文描述ASP.NET W ...
- CODE - TSQL convert Query to JSON
原文 ODE - TSQL convert Query to JSON TSQL - Query to JSON It is my philosophy that good development s ...
- 字符串json转换为xml xml转换json
原文:字符串json转换为xml xml转换json // To convert an XML node contained in string xml into a JSON string XmlD ...
- ASP.NET Web API中的JSON和XML序列化
ASP.NET Web API中的JSON和XML序列化 前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs.com/aehyok ...
- 转 JSON与XML转换
这两天处理模块的联调工作,在json与XML转换中出现了一些奇怪的问题,仔细究来,实为对org.json.*包知之太少.晚上baidu.google一下,找出了问题出现的原因.在模块中,使用了两个方法 ...
- json to xml
/* This work is licensed under Creative Commons GNU LGPL License. License: http://creativecommons.or ...
- Spring 梳理 - View - JSON and XML View
实际案例json <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...
随机推荐
- python3实现二叉树的遍历与递归算法解析
1.二叉树的三种遍历方式 二叉树有三种遍历方式:先序遍历,中序遍历,后续遍历 即:先中后指的是访问根节点的顺序 eg:先序 根左右 中序 左根右 后序 左右根 遍历总体思路:将树分成最小 ...
- day 58 bootstrap part2
bootstrap组件的官网, https://v3.bootcss.com/components/#page-header 在bootstrap里面出了HTML和css样式之外还有很多的辅助工具,我 ...
- Python3 序列解包
转载自:https://blog.csdn.net/yilovexing/article/details/80576788 序列解包是 Python 3.0 之后才有的语法 什么是序列解包呢?先看一个 ...
- Codeforces 208A-Dubstep(字符串)
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performanc ...
- NSL:SOFM神经网络实现预测哪个样本与哪个样本处在同一层,从而科学规避我国煤矿突水灾难—Jason niu
load water_data.mat attributes = mapminmax(attributes); P_train = attributes(:,1:35); T_train = clas ...
- a标签点击不跳转的几种方法
a标签点击不跳转的几种方法 1.onclick事件中返回false <a href="http://www.baidu.com" onclick="return f ...
- Django2.0引入css、js、img文件
Django2.0引入css.js.img文件 一.文件结构 二.settings.py的配置 # Static files (CSS, JavaScript, Images) # https://d ...
- Django之Form组件(一)
Django之Form组件(一) Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 基本操作:字 ...
- 现代C++之理解模板类型推断(template type deduction)
理解模板类型推断(template type deduction) 我们往往不能理解一个复杂的系统是如何运作的,但是却知道这个系统能够做什么.C++的模板类型推断便是如此,把参数传递到模板函数往往能让 ...
- JVM 调优-给你的java应用看看病
目录 java 应用 1 cpu 负载过高 1.1 分析问题 1.2 解决方案 2 内存占用过多 2.1 从内存回收方面 2.2 从代码层面 java 应用 1 cpu 负载过高 1.1 分析问题 首 ...