为了账号安全,请及时绑定邮箱和手机立即绑定

请问下如何能把数据库中的数据转化成json格式然后在网页中调用,不用php

请问下如何能把数据库中的数据转化成json格式然后在网页中调用,不用php

查看完整描述

2 回答

已采纳
?
慕勒0069038

TA贡献143条经验 获得超39个赞

public String resultSetToJson(ResultSet rs) throws SQLException,JSONException  

{  

   // json数组  

   JSONArray array = new JSONArray();  

    

   // 获取列数  

   ResultSetMetaData metaData = rs.getMetaData();  

   int columnCount = metaData.getColumnCount();  

    

   // 遍历ResultSet中的每条数据  

    while (rs.next()) {  

        JSONObject jsonObj = new JSONObject();  

         

        // 遍历每一列  

        for (int i = 1; i <= columnCount; i++) {  

            String columnName =metaData.getColumnLabel(i);  

            String value = rs.getString(columnName);  

            jsonObj.put(columnName, value);  

        }   

        array.put(jsonObj);   

    }  

    

   return array.toString();  

}  


查看完整回答
1 反对 回复 2017-04-17
?
慕瓜9220888

TA贡献868条经验 获得超0个赞

WFXAQRAOT

KPDRSPAUS

IPMTUVGYA

GIJLBTNPX

GKHUWDKXO

HMJTTKOMK

OHEQAXTZG

PBULHTKKE

WTMBDBKNY

NPERRUXDQ

VEWOGTMVY

XLHMEXPYC

FKWTFYRZG

RAKZYLHCS

QVSKXORCO

TXDZHGLLF

KLWIAQGHE

NLUGOUUYL

NVEGIVASP

OOBJBJSGG

MUDCLITWI

QTVSAHZCK

AIWMUUPMG

NWPVYXLEI

YONKARYIG

SAAQGGJLZ

VONWIVZSD

ZOYXLVUBS

TNCRZXXAF

SKEWLJHFD

OXDOWAWSF

RVXJVZKTX

RGCUAZFCC

VLBOGAADR

TJJCUGDDX

FBNMFPSFL

EQXFUAHPJ

ILAILIIQA

TWLHNHKPC

IXQMIKCDN

MKEMYEKCP

DJFCLJBRB

SIBSSPGNU

XZODDTNNO

HMBKCLCIT

JAQZRYCZF

RFBENUBZJ

POGGIIPWG

GCRASPTPJ

HFIXGAAHH

KZBAJADOY

LTMEARAQB

LQSIAOOVP

EVONQGNYB

IAFEXJAAK

YAHQZWJQP

JAJSVVMMD

CQFVXRYSC

QOXQJTCCT

YAJRURYIS

YELXDDMWG

PWOHTURRB

RGZRHHOVM

BRRQPPGGX

NPIKQWTAJ

CKTVOBSGA

UFEDQDTKR

PTCBUPMJU

SACFPGDMT

MBYLDURLK

QRIHGHOYP

FNMLKROFP

KSORGHXVF

ZXGTAXGXH

LJBKAKXOY

AGPOOYOPJ

RGVRGNOOY

MWWOEBOYP

CQFOXUTKK

CJFVUCEQT

TBCUGVYRO

FNFRVHDUF

ITMTDGJJD

TEXGJGRAL

MTCINUNFF

AKXDCADBF

JYKESNXDO

FHDJGTNGL

LOVNMCFSO

ZUDPEXPQE

PGZXPPISM

DMTMJUPJA

UPKAREOKH

NUQIEBQQH

WAJFUUKOL

SWLBQDXNK

JUSRNAEFR

MASYDDJAR

GILASFQXL

JLQWYLDND

JFBQYIZTW

GIACOBBNC

CHMWYOAKR

ZERJORRKY

GLHOFMVQN

FALQIYADR

HLNPHBHXA

ZHJVXZCFL

OGSHYBWYF

GOTNUKYZN

DKTIELSKE

XFWGCWJEB

TIZIBMHXW

JKYPTKUTI

OIPQWFDLI

DDJJDSNVS

DGDQUIZOD

WYFSHVDVK

PPMORIGMM

HQKXNFPGA

JSLKWGXNA

YGSRDAHYY

TIXJLCYOZ

RFMSLSFVV

RWYLNGGDX

KSBVEQZWE

ZLFLRVFCA

LNHQGHOWC

JVHMVFHNH

AIRNBPSWQ

DIOTYYRAP

RWINCLBJT

VNWUUUUGV

CQJYXZHAY

UBNHWCROO

RMUGRQTQW

RGPBEEEZP

RCZTJKMTV

PDCPTBFFX

MKJYQNXNA

ZHBLUPNRM

EFVSHFWPW

GBXZGZPPW

ZBXBADGAK

BDIAJDQQE

PDYVVYSIJ

MYHKZMPPZ

GNYYISDOL

WAWRKOVRL

OPYEDTENY

NYEAGTGCY

PTZLBEZZV

YZFPEKORI

FQMYGHKNY

OVCYLZYNI

MDZBTJUCT

URAZXICWA

XZGIVMTTN

KSMEWJWQW

HIOSHUXRI

CUOPROVGU

UGPBHUTMD

SZOIXGXQU

HBUGIBIBV

ZRGMKHBXU

IVUCEJGXQ

WDDYOBHUD

UTAWIJVSM

LYCMGHSZQ

XKXECFJRF

WPNKXYBXS

ONEAWBIDP

KJJFOCNLP

FBFUOPQHH

RPAFRCDEV

DWTWFXVUL

ZRTNTXSFK

WDKJKXTDK

YHHGDHCMR

FFZXGZJEG

查看完整回答
反对 回复 2021-10-19
  • 2 回答
  • 0 关注
  • 2989 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信