Clob与String互转

    技术2023-07-23  69

    import com.alibaba.fastjson.JSON; import javax.sql.rowset.serial.SerialClob; import java.sql.Clob; import java.sql.SQLException; import java.util.Map; public class Test { public static void main(String[] args) throws SQLException { Clob clob = null; try { //String 转Clob String str = "{\"houseInfoList\":[{\"houseAddress\":\"郑州高新技术产业开发区人民法院\",\"houseNumber\":\"123456789\",\"endTime\":\"2020-01-12 00:00:00\",\"closedRegisterTime\":\"2017-01-13 11:52:21\",\"constructionArea\":\"100\"},{\"houseAddress\":\"郑州市金水区人民法院\",\"houseNumber\":\"88888\",\"endTime\":\"2020-08-08 00:00:00\",\"closedRegisterTime\":\"2017-08-09 14:58:54\",\"constructionArea\":\"100\"},{\"houseAddress\":\"郑州市中级人民法院\",\"houseNumber\":\"77777\",\"houseAddress\":\"2021-02-06 00:00:00\",\"closedRegisterTime\":\"2018-02-07 15:56:37\",\"constructionArea\":\"100\"},{\"houseAddress\":\"郑州航空港经济综合实验区人民法院\",\"houseNumber\":\"77777\",\"endTime\":\"2021-07-31 00:00:00\",\"closedRegisterTime\":\"2018-08-01 15:23:31\",\"constructionArea\":\"100\"}]}"; clob = new SerialClob(str.toCharArray()); } catch (SQLException e) { e.printStackTrace(); } // Clob转String String content = clob.getSubString((long) 1, (int) clob.length()); Map data = (Map) JSON.parse(content); } }

     

    Processed: 0.020, SQL: 9