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的更多相关文章

  1. staxon实现json和xml互转

    pom.xml: <dependency> <groupId>de.odysseus.staxon</groupId> <artifactId>stax ...

  2. 【ASP.NET Web API教程】6.2 ASP.NET Web API中的JSON和XML序列化

    谨以此文感谢关注此系列文章的园友!前段时间本以为此系列文章已没多少人关注,而不打算继续下去了.因为文章贴出来之后,看的人似乎不多,也很少有人对这些文章发表评论,而且几乎无人给予“推荐”.但前几天有人询 ...

  3. 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 ...

  4. CODE - TSQL convert Query to JSON

    原文 ODE - TSQL convert Query to JSON TSQL - Query to JSON It is my philosophy that good development s ...

  5. 字符串json转换为xml xml转换json

    原文:字符串json转换为xml xml转换json // To convert an XML node contained in string xml into a JSON string XmlD ...

  6. ASP.NET Web API中的JSON和XML序列化

    ASP.NET Web API中的JSON和XML序列化 前言 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnblogs.com/aehyok ...

  7. 转 JSON与XML转换

    这两天处理模块的联调工作,在json与XML转换中出现了一些奇怪的问题,仔细究来,实为对org.json.*包知之太少.晚上baidu.google一下,找出了问题出现的原因.在模块中,使用了两个方法 ...

  8. json to xml

    /* This work is licensed under Creative Commons GNU LGPL License. License: http://creativecommons.or ...

  9. Spring 梳理 - View - JSON and XML View

    实际案例json <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...

随机推荐

  1. 001 Hello Security 的框架搭建

    一:STS 1.下载STS 官网:http://spring.io/tools 使用一个干净的STS进行操作学习. 2.jdk检查 3.添加自己的maven 4.使用tomcat 二:新建项目 1.新 ...

  2. Uniform Generator

    Computer simulations often require random numbers. One way to generate pseudo-random numbers is via ...

  3. Qt程序继承QApplication发生崩溃的原因

    一.前情介绍 QApplication是Qt开发中经常用到的一个类,用来管理应用程序的生命周期.跟其相关的类还有QCoreApplication和QGuiApplication,分别用于不同场景下为应 ...

  4. java菜鸟之微信分享

    前言:我终于理解了什么叫做教科书:教科书就是把一些简单容易的知识写成一堆谁都看不懂的书,这,就简称“教科书” 这些天接触到微信分享以及回调的问题,因为之前没接触过,所以这次做这个分享,碰了一点点壁,特 ...

  5. 2189 ACM 母函数 素数

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2189 思路:先找出150以内的 素数,然后再用母函数或01背包计算 复习母函数的代码:https://ww ...

  6. 解决IDEA Springboot项目sql文件打开提示No data sources are configured to run this SQL and provide advanced的问题

    Idea2018的Springboot项目,如果里面有.sql文件,打开后,会提示"No data sources are configured to run this SQL and pr ...

  7. div height 自适应高度 占满剩余高度的方法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. yii2 创建模块modules

    方案一:如果模块儿较少,不用专门给模块儿目录定义别名,酱紫做就ok啦. 1.在项目根目录下面创建一个 modules 目录. 2.进入 gii : http://localhost/basic/web ...

  9. 函数(二):input、raw_input、lambda、repr、map、filter、reduce、eval、exec、range、xrange

    一.input()和raw_input(): input()支持用户输入数字或表达式,按类型存或存表达式的计算结果 raw_input():输入所有内容当成字符串存 二.lambda函数:匿名函数 l ...

  10. Adaboost 算法实例解析

    Adaboost 算法实例解析 1 Adaboost的原理 1.1 Adaboost基本介绍 AdaBoost,是英文"Adaptive Boosting"(自适应增强)的缩写,由 ...