Here you can find the source of convertResultSetToJSON(ResultSet resultSet)
Parameter | Description |
---|---|
resultSet | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static JSONArray convertResultSetToJSON(ResultSet resultSet) throws Exception
//package com.java2s; //License from project: Apache License import java.sql.ResultSet; import org.json.JSONArray; import org.json.JSONObject; public class Main { /**//www . j av a 2 s. co m * Convert a result set into a JSON Array * * @param resultSet * @return a JSONArray * @throws Exception */ public static JSONArray convertResultSetToJSON(ResultSet resultSet) throws Exception { JSONArray jsonArray = new JSONArray(); if (resultSet != null) { while (resultSet.next()) { int total_rows = resultSet.getMetaData().getColumnCount(); JSONObject obj = new JSONObject(); for (int i = 0; i < total_rows; i++) { int colNextIndex = i + 1; obj.put(resultSet.getMetaData().getColumnLabel(colNextIndex).toLowerCase(), resultSet.getObject(colNextIndex)); } jsonArray.put(obj); } } return jsonArray; } }