public String resultSetToJson(ResultSet rs) throws SQLException,JSONException
{
// json数组
JSONArray array = new JSONArray();
// 获取列数
ResultSetMetaData metaData = ();
int columnCount = ();
// 遍历ResultSet中的每条数据
while (()) {
JSONObject jsonObj = new JSONObject();
// 遍历每一列
for (int i = 1; i <= columnCount; i++) {
String columnName =(i);
String value = (columnName);
(columnName, value);
}
(jsonObj);
}
return ();
}
需要用到的jar包为包
实测很方便,新手基本看一眼代码就能运用,但是我在转成json串之后输出的时候,所有的字段名字都是大写,不知道什么原因,只能再加上一句话,转成小写
columnName = (); //转化成小写